@@ -1547,30 +1547,38 @@ describe('Cloud Code', () => {
1547
1547
} ) ;
1548
1548
1549
1549
describe ( 'cloud jobs' , ( ) => {
1550
- it ( 'should define a job' , done => {
1551
- expect ( ( ) => {
1552
- Parse . Cloud . job ( 'myJob' , ( { message } ) => {
1553
- message ( 'Hello, world!!!' ) ;
1554
- } ) ;
1555
- } ) . not . toThrow ( ) ;
1550
+ for ( let x = 0 ; x < 1000 ; x ++ ) {
1551
+ fit ( 'should define a job' , done => {
1552
+ expect ( ( ) => {
1553
+ Parse . Cloud . job ( 'myJob' , ( { message } ) => {
1554
+ message ( 'Hello, world!!!' ) ;
1555
+ } ) ;
1556
+ } ) . not . toThrow ( ) ;
1556
1557
1557
- request ( {
1558
- method : 'POST' ,
1559
- url : 'http://localhost:8378/1/jobs/myJob' ,
1560
- headers : {
1561
- 'X-Parse-Application-Id' : Parse . applicationId ,
1562
- 'X-Parse-Master-Key' : Parse . masterKey ,
1563
- } ,
1564
- } ) . then (
1565
- ( ) => {
1566
- done ( ) ;
1567
- } ,
1568
- err => {
1569
- fail ( err ) ;
1570
- done ( ) ;
1571
- }
1572
- ) ;
1573
- } ) ;
1558
+ request ( {
1559
+ method : 'POST' ,
1560
+ url : 'http://localhost:8378/1/jobs/myJob' ,
1561
+ headers : {
1562
+ 'X-Parse-Application-Id' : Parse . applicationId ,
1563
+ 'X-Parse-Master-Key' : Parse . masterKey ,
1564
+ } ,
1565
+ } )
1566
+ . then ( async response => {
1567
+ const jobStatusId = response . headers [ 'x-parse-job-status-id' ] ;
1568
+ const checkJobStatus = async ( ) => {
1569
+ const jobStatus = await new Parse . Query ( '_JobStatus' ) . get ( jobStatusId , {
1570
+ useMasterKey : true ,
1571
+ } ) ;
1572
+ return jobStatus . get ( 'finishedAt' ) && jobStatus . get ( 'message' ) === 'Hello, world!!!' ;
1573
+ } ;
1574
+ while ( ! ( await checkJobStatus ( ) ) ) {
1575
+ await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
1576
+ }
1577
+ } )
1578
+ . then ( done )
1579
+ . catch ( done . fail ) ;
1580
+ } ) ;
1581
+ }
1574
1582
1575
1583
it ( 'should not run without master key' , done => {
1576
1584
expect ( ( ) => {
0 commit comments