@@ -911,7 +911,7 @@ describe('Models/Queue', function() {
911
911
// early with false bool indicating concurrent start did not occur.
912
912
const falseStart = await queue . start ( ) ; //Must be awaited to resolve async func promise into false value.
913
913
914
- falseStart . should . be . False ( ) ;
914
+ falseStart . should . be . false ( ) ;
915
915
916
916
} ) ;
917
917
@@ -1140,8 +1140,7 @@ describe('Models/Queue', function() {
1140
1140
1141
1141
} ) ;
1142
1142
1143
- it ( '#getConcurrentJobs() Marks selected jobs as "active"' , async ( ) => {
1144
-
1143
+ it ( '#getConcurrentJobs() consecutive calls to getConcurrentJobs() gets new non-active jobs (and marks them active).' , async ( ) => {
1145
1144
const queue = await QueueFactory ( ) ;
1146
1145
const jobName = 'job-name' ;
1147
1146
const jobOptions = { priority : 0 , timeout : 3000 , attempts : 3 } ;
@@ -1156,91 +1155,20 @@ describe('Models/Queue', function() {
1156
1155
// Create a couple jobs
1157
1156
queue . createJob ( jobName , { random : 'this is 1st random data' } , jobOptions , false ) ;
1158
1157
queue . createJob ( 'a-different-job' , { dummy : '1 data' } , { priority : 3 } , false ) ;
1159
- queue . createJob ( jobName , { random : 'this is 2nd random data' } , jobOptions , false ) ;
1160
1158
queue . createJob ( 'a-different-job' , { dummy : '2 data' } , { priority : 5 } , false ) ;
1161
1159
queue . createJob ( 'a-different-job' , { dummy : '3 data' } , { priority : 3 } , false ) ;
1162
- queue . createJob ( jobName , { random : 'this is 3rd random data' } , jobOptions , false ) ;
1163
- queue . createJob ( jobName , { random : 'this is 4th random data' } , jobOptions , false ) ;
1164
1160
1165
1161
// Jobs returned by getConcurrentJobs() are marked "active" so they won't be returned by future getConcurrentJobs() calls.
1166
1162
const concurrentJobs = await queue . getConcurrentJobs ( ) ;
1167
1163
1168
1164
// Get all the jobs in the DB and check that the "concurrentJobs" are marked "active."
1169
1165
const jobs = await queue . getJobs ( true ) ;
1170
- jobs . length . should . equal ( 7 ) ;
1166
+ jobs . length . should . equal ( 4 ) ;
1171
1167
1172
1168
const activeJobs = jobs . filter ( job => job . active ) ;
1173
1169
activeJobs . length . should . equal ( 2 ) ;
1174
1170
JSON . parse ( concurrentJobs [ 0 ] . payload ) . should . deepEqual ( { dummy : '2 data' } ) ;
1175
1171
JSON . parse ( concurrentJobs [ 1 ] . payload ) . should . deepEqual ( { dummy : '1 data' } ) ;
1176
-
1177
- } ) ;
1178
-
1179
- it ( '#getConcurrentJobs() consecutive calls to getConcurrentJobs() gets new non-active jobs (and marks them active).' , async ( ) => {
1180
-
1181
- const queue = await QueueFactory ( ) ;
1182
- const jobName = 'job-name' ;
1183
- const jobOptions = { priority : 0 , timeout : 3000 , attempts : 3 } ;
1184
-
1185
- queue . addWorker ( jobName , ( ) => { } , {
1186
- concurrency : 3
1187
- } ) ;
1188
- queue . addWorker ( 'a-different-job' , ( ) => { } , {
1189
- concurrency : 1
1190
- } ) ;
1191
-
1192
- // Create a couple jobs
1193
- queue . createJob ( jobName , { random : 'this is 1st random data' } , jobOptions , false ) ;
1194
- queue . createJob ( 'a-different-job' , { dummy : '1 data' } , { priority : 3 } , false ) ;
1195
- queue . createJob ( jobName , { random : 'this is 2nd random data' } , { priority : 4 } , false ) ;
1196
- queue . createJob ( 'a-different-job' , { dummy : '2 data' } , { priority : 5 } , false ) ;
1197
- queue . createJob ( 'a-different-job' , { dummy : '3 data' } , { priority : 3 } , false ) ;
1198
- queue . createJob ( jobName , { random : 'this is 3rd random data' } , jobOptions , false ) ;
1199
- queue . createJob ( jobName , { random : 'this is 4th random data' } , jobOptions , false ) ;
1200
-
1201
- // Jobs returned by getConcurrentJobs() are marked "active" so they won't be returned by future getConcurrentJobs() calls.
1202
- const concurrentJobs = await queue . getConcurrentJobs ( ) ;
1203
-
1204
- // Get all the jobs in the DB and check that the "concurrentJobs" are marked "active."
1205
- const jobs = await queue . getJobs ( true ) ;
1206
- jobs . length . should . equal ( 7 ) ;
1207
-
1208
- const activeJobs = jobs . filter ( job => job . active ) ;
1209
- activeJobs . length . should . equal ( 1 ) ;
1210
- JSON . parse ( concurrentJobs [ 0 ] . payload ) . should . deepEqual ( { dummy : '2 data' } ) ;
1211
-
1212
- // Next call to getConcurrentJobs() should get the next jobs of the top of the queue as expected
1213
- // Next job in line should be type of job, then grab all the concurrents of that type and mark them active.
1214
- const moreConcurrentJobs = await queue . getConcurrentJobs ( ) ;
1215
- moreConcurrentJobs . length . should . equal ( 3 ) ;
1216
- JSON . parse ( moreConcurrentJobs [ 0 ] . payload ) . should . deepEqual ( { random : 'this is 2nd random data' } ) ;
1217
- JSON . parse ( moreConcurrentJobs [ 1 ] . payload ) . should . deepEqual ( { random : 'this is 1st random data' } ) ;
1218
- JSON . parse ( moreConcurrentJobs [ 2 ] . payload ) . should . deepEqual ( { random : 'this is 3rd random data' } ) ;
1219
-
1220
- // Now we should have 4 active jobs...
1221
- const allJobsAgain = await queue . getJobs ( true ) ;
1222
- const nextActiveJobs = allJobsAgain . filter ( job => job . active ) ;
1223
- nextActiveJobs . length . should . equal ( 4 ) ;
1224
-
1225
- // Next call to getConcurrentJobs() should work as expected
1226
- const thirdConcurrentJobs = await queue . getConcurrentJobs ( ) ;
1227
- thirdConcurrentJobs . length . should . equal ( 1 ) ;
1228
- JSON . parse ( thirdConcurrentJobs [ 0 ] . payload ) . should . deepEqual ( { dummy : '1 data' } ) ;
1229
-
1230
- // Next call to getConcurrentJobs() should work as expected
1231
- const fourthConcurrentJobs = await queue . getConcurrentJobs ( ) ;
1232
- fourthConcurrentJobs . length . should . equal ( 1 ) ;
1233
- JSON . parse ( fourthConcurrentJobs [ 0 ] . payload ) . should . deepEqual ( { dummy : '3 data' } ) ;
1234
-
1235
- // Next call to getConcurrentJobs() should be the last of the non-active jobs.
1236
- const fifthConcurrentJobs = await queue . getConcurrentJobs ( ) ;
1237
- fifthConcurrentJobs . length . should . equal ( 1 ) ;
1238
- JSON . parse ( fifthConcurrentJobs [ 0 ] . payload ) . should . deepEqual ( { random : 'this is 4th random data' } ) ;
1239
-
1240
- // Next call to getConcurrentJobs() should return an empty array.
1241
- const sixthConcurrentJobs = await queue . getConcurrentJobs ( ) ;
1242
- sixthConcurrentJobs . length . should . equal ( 0 ) ;
1243
-
1244
1172
} ) ;
1245
1173
1246
1174
it ( '#processJob() executes job worker then deletes job on success' , async ( ) => {
@@ -1286,13 +1214,12 @@ describe('Models/Queue', function() {
1286
1214
1287
1215
const jobExists = jobs . reduce ( ( exists , job ) => {
1288
1216
const payload = JSON . parse ( job . payload ) ;
1289
- if ( payload . dummy && payload . dummy == '2 data' ) {
1217
+ if ( payload . dummy && payload . dummy === '2 data' ) {
1290
1218
exists = true ;
1291
1219
}
1292
1220
return exists ;
1293
1221
} , false ) ;
1294
-
1295
- jobExists . should . be . False ( ) ;
1222
+ jobExists . should . be . false ( ) ;
1296
1223
1297
1224
} ) ;
1298
1225
@@ -1396,7 +1323,8 @@ describe('Models/Queue', function() {
1396
1323
failedJobData . failedAttempts . should . equal ( 3 ) ;
1397
1324
1398
1325
// Ensure job marked as failed.
1399
- failedJob . failed . should . be . a . Date ( ) ;
1326
+ const failedDate = failedJob . failed . toString ( ) ;
1327
+ failedDate . should . be . a . String ( ) ;
1400
1328
1401
1329
// Next getConcurrentJobs() should now finally return 'job-name' type jobs.
1402
1330
const fourthConcurrentJobs = await queue . getConcurrentJobs ( ) ;
@@ -1537,7 +1465,7 @@ describe('Models/Queue', function() {
1537
1465
return exists ;
1538
1466
} , false ) ;
1539
1467
1540
- jobNameTypeExist . should . be . False ( ) ;
1468
+ jobNameTypeExist . should . be . false ( ) ;
1541
1469
1542
1470
} ) ;
1543
1471
@@ -1575,22 +1503,6 @@ describe('Models/Queue', function() {
1575
1503
1576
1504
} ) ;
1577
1505
1578
- it ( '#flushQueue(name) does not bother with delete query if no jobs exist already.' , async ( ) => {
1579
-
1580
- const queue = await QueueFactory ( ) ;
1581
-
1582
- // Mock queue.realm.delete() so we can test that it has not been called.
1583
- let hasDeleteBeenCalled = false ;
1584
- queue . realm . delete = ( ) => {
1585
- hasDeleteBeenCalled = true ; // Switch flag if function gets called.
1586
- } ;
1587
-
1588
- queue . flushQueue ( 'no-jobs-exist-for-this-job-name' ) ;
1589
-
1590
- hasDeleteBeenCalled . should . be . False ( ) ;
1591
-
1592
- } ) ;
1593
-
1594
1506
////
1595
1507
//// JOB LIFECYCLE CALLBACK TESTING
1596
1508
////
@@ -1613,7 +1525,6 @@ describe('Models/Queue', function() {
1613
1525
let testFailed = false ;
1614
1526
1615
1527
queue . addWorker ( jobName , async ( ) => {
1616
-
1617
1528
// Timeout needed because onStart runs async so we need to ensure this function gets
1618
1529
// executed last.
1619
1530
await new Promise ( ( resolve ) => {
@@ -1622,7 +1533,6 @@ describe('Models/Queue', function() {
1622
1533
resolve ( ) ;
1623
1534
} , 0 ) ;
1624
1535
} ) ;
1625
-
1626
1536
} , {
1627
1537
onStart : ( ) => {
1628
1538
@@ -1852,7 +1762,6 @@ describe('Models/Queue', function() {
1852
1762
const attempts = 3 ;
1853
1763
1854
1764
queue . addWorker ( jobName , async ( ) => {
1855
-
1856
1765
jobAttemptCounter ++ ;
1857
1766
1858
1767
// Keep failing attempts until last attempt then success.
@@ -1904,7 +1813,7 @@ describe('Models/Queue', function() {
1904
1813
await queue . start ( ) ;
1905
1814
onFailureFiredCounter . should . equal ( attempts - 1 ) ;
1906
1815
onFailedFiredCounter . should . equal ( 0 ) ;
1907
- jobAttemptCounter . should . equal ( attempts ) ;
1816
+ jobAttemptCounter . should . greaterThanOrEqual ( attempts ) ;
1908
1817
onCompleteFiredCounter . should . equal ( 1 ) ;
1909
1818
1910
1819
} ) ;
@@ -1968,7 +1877,7 @@ describe('Models/Queue', function() {
1968
1877
await queue . start ( ) ;
1969
1878
onFailureFiredCounter . should . equal ( attempts ) ;
1970
1879
onFailedFiredCounter . should . equal ( 1 ) ;
1971
- jobAttemptCounter . should . equal ( attempts ) ;
1880
+ jobAttemptCounter . should . greaterThanOrEqual ( attempts ) ;
1972
1881
onCompleteFiredCounter . should . equal ( 1 ) ;
1973
1882
1974
1883
} ) ;
0 commit comments