@@ -510,9 +510,17 @@ describe('workers', function () {
510
510
await worker . close ( ) ;
511
511
} ) ;
512
512
513
- it ( 'do not call moveToActive more than number of jobs + 1 ' , async ( ) => {
513
+ it ( 'do not call moveToActive more than number of jobs + 2 ' , async ( ) => {
514
514
const numJobs = 50 ;
515
515
let completedJobs = 0 ;
516
+
517
+ const jobs : Promise < Job > [ ] = [ ] ;
518
+ for ( let i = 0 ; i < numJobs ; i ++ ) {
519
+ jobs . push ( queue . add ( 'test' , { foo : 'bar' } ) ) ;
520
+ }
521
+
522
+ await Promise . all ( jobs ) ;
523
+
516
524
const worker = new Worker (
517
525
queueName ,
518
526
async job => {
@@ -521,22 +529,16 @@ describe('workers', function () {
521
529
} ,
522
530
{ connection, prefix, concurrency : 100 } ,
523
531
) ;
524
- await worker . waitUntilReady ( ) ;
525
532
526
533
// Add spy to worker.moveToActive
527
534
const spy = sinon . spy ( worker , 'moveToActive' ) ;
528
535
const bclientSpy = sinon . spy (
529
536
await worker . blockingConnection . client ,
530
537
'bzpopmin' ,
531
538
) ;
539
+ await worker . waitUntilReady ( ) ;
532
540
533
- for ( let i = 0 ; i < numJobs ; i ++ ) {
534
- const job = await queue . add ( 'test' , { foo : 'bar' } ) ;
535
- expect ( job . id ) . to . be . ok ;
536
- expect ( job . data . foo ) . to . be . eql ( 'bar' ) ;
537
- }
538
-
539
- expect ( bclientSpy . callCount ) . to . be . equal ( 1 ) ;
541
+ expect ( bclientSpy . callCount ) . to . be . equal ( 0 ) ;
540
542
541
543
await new Promise < void > ( ( resolve , reject ) => {
542
544
worker . on ( 'completed' , ( job : Job , result : any ) => {
@@ -547,9 +549,11 @@ describe('workers', function () {
547
549
} ) ;
548
550
} ) ;
549
551
552
+ expect ( completedJobs ) . to . be . equal ( numJobs ) ;
553
+ expect ( bclientSpy . callCount ) . to . be . equal ( 2 ) ;
554
+
550
555
// Check moveToActive was called numJobs + 2 times
551
556
expect ( spy . callCount ) . to . be . equal ( numJobs + 2 ) ;
552
- expect ( bclientSpy . callCount ) . to . be . equal ( 3 ) ;
553
557
554
558
await worker . close ( ) ;
555
559
} ) ;
0 commit comments