@@ -27,15 +27,13 @@ describe('queue', function(){
27
27
it ( 'should call the unsaturated callback if tasks length is less than concurrency minus buffer' , function ( done ) {
28
28
var calls = [ ] ;
29
29
var q = async . queue ( function ( task , cb ) {
30
- // nop
31
- calls . push ( 'process ' + task ) ;
32
30
async . setImmediate ( cb ) ;
33
31
} , 10 ) ;
34
32
q . unsaturated = function ( ) {
35
33
calls . push ( 'unsaturated' ) ;
36
34
} ;
37
35
q . empty = function ( ) {
38
- expect ( calls . indexOf ( 'unsaturated' ) ) . to . be . above ( - 1 ) ;
36
+ expect ( calls . length ) . to . equal ( 5 )
39
37
done ( ) ;
40
38
} ;
41
39
q . push ( 'foo0' , function ( ) { calls . push ( 'foo0 cb' ) ; } ) ;
@@ -44,6 +42,38 @@ describe('queue', function(){
44
42
q . push ( 'foo3' , function ( ) { calls . push ( 'foo3 cb' ) ; } ) ;
45
43
q . push ( 'foo4' , function ( ) { calls . push ( 'foo4 cb' ) ; } ) ;
46
44
} ) ;
45
+ it ( 'should call the unsaturated callback if the queue is not saturated after being saturated' , function ( done ) {
46
+ var calls = [ ] ;
47
+ var expectedArray = [ 'saturated' ,
48
+ 'unsaturated' ,
49
+ 'unsaturated' ,
50
+ 'unsaturated' ,
51
+ 'unsaturated' ,
52
+ 'unsaturated' ]
53
+ var q = async . queue ( function ( task , cb ) {
54
+ async . setImmediate ( cb ) ;
55
+ } , 1 ) ;
56
+ q . unsaturated = function ( ) {
57
+ calls . push ( 'unsaturated' ) ;
58
+ } ;
59
+ q . saturated = function ( ) {
60
+ calls . push ( 'saturated' ) ;
61
+ q . concurrency = 10 ;
62
+ } ;
63
+ q . empty = function ( ) {
64
+ var saturated = calls . filter ( function ( value ) {
65
+ return value === 'saturated' ;
66
+ j } ) ;
67
+ expect ( saturated . length ) . to . be . equal ( 1 ) ;
68
+ expect ( calls ) . to . deep . equal ( expectedArray ) ;
69
+ done ( ) ;
70
+ } ;
71
+ q . push ( 'foo0' , function ( ) { calls . push ( 'foo0 cb' ) ; } ) ;
72
+ q . push ( 'foo1' , function ( ) { calls . push ( 'foo1 cb' ) ; } ) ;
73
+ q . push ( 'foo2' , function ( ) { calls . push ( 'foo2 cb' ) ; } ) ;
74
+ q . push ( 'foo3' , function ( ) { calls . push ( 'foo3 cb' ) ; } ) ;
75
+ q . push ( 'foo4' , function ( ) { calls . push ( 'foo4 cb' ) ; } ) ;
76
+ } ) ;
47
77
} ) ;
48
78
} ) ;
49
79
0 commit comments