@@ -2878,59 +2878,39 @@ exports['queue'] = {
28782878 } ) ;
28792879} ,
28802880
2881+ // The original queue implementation allowed the concurrency to be changed only
2882+ // on the same event loop during which a task was added to the queue. This
2883+ // test attempts to be a more rubust test.
2884+ // Start with a concurrency of 1. Wait until a leter event loop and change
2885+ // the concurrency to 2. Wait again for a later loop then verify the concurrency.
2886+ // Repeat that one more time by chaning the concurrency to 5.
28812887'changing concurrency' : function ( test ) {
2882- var call_order = [ ] ,
2883- delays = [ 40 , 20 , 60 , 20 ] ;
2884-
2885- // worker1: --1-2---3-4
2886- // order of completion: 1,2,3,4
2887-
2888- var q = async . queue ( function ( task , callback ) {
2889- setTimeout ( function ( ) {
2890- call_order . push ( 'process ' + task ) ;
2891- callback ( 'error' , 'arg' ) ;
2892- } , delays . splice ( 0 , 1 ) [ 0 ] ) ;
2893- } , 2 ) ;
2894-
2895- q . push ( 1 , function ( err , arg ) {
2896- test . equal ( err , 'error' ) ;
2897- test . equal ( arg , 'arg' ) ;
2898- test . equal ( q . length ( ) , 3 ) ;
2899- call_order . push ( 'callback ' + 1 ) ;
2900- } ) ;
2901- q . push ( 2 , function ( err , arg ) {
2902- test . equal ( err , 'error' ) ;
2903- test . equal ( arg , 'arg' ) ;
2904- test . equal ( q . length ( ) , 2 ) ;
2905- call_order . push ( 'callback ' + 2 ) ;
2906- } ) ;
2907- q . push ( 3 , function ( err , arg ) {
2908- test . equal ( err , 'error' ) ;
2909- test . equal ( arg , 'arg' ) ;
2910- test . equal ( q . length ( ) , 1 ) ;
2911- call_order . push ( 'callback ' + 3 ) ;
2912- } ) ;
2913- q . push ( 4 , function ( err , arg ) {
2914- test . equal ( err , 'error' ) ;
2915- test . equal ( arg , 'arg' ) ;
2916- test . equal ( q . length ( ) , 0 ) ;
2917- call_order . push ( 'callback ' + 4 ) ;
2918- } ) ;
2919- test . equal ( q . length ( ) , 4 ) ;
2920- test . equal ( q . concurrency , 2 ) ;
2921- q . concurrency = 1 ;
2922-
2923- setTimeout ( function ( ) {
2924- test . same ( call_order , [
2925- 'process 1' , 'callback 1' ,
2926- 'process 2' , 'callback 2' ,
2927- 'process 3' , 'callback 3' ,
2928- 'process 4' , 'callback 4'
2929- ] ) ;
2930- test . equal ( q . concurrency , 1 ) ;
2931- test . equal ( q . length ( ) , 0 ) ;
2888+
2889+ var q = async . queue ( function ( task , callback ) {
2890+ setTimeout ( function ( ) {
2891+ callback ( ) ;
2892+ } , 100 ) ;
2893+ } , 1 ) ;
2894+
2895+ for ( var i = 0 ; i < 50 ; i ++ ) {
2896+ q . push ( '' ) ;
2897+ }
2898+
2899+ q . drain = function ( ) {
29322900 test . done ( ) ;
2933- } , 250 ) ;
2901+ } ;
2902+
2903+ setTimeout ( function ( ) {
2904+ test . equal ( q . concurrency , 1 ) ;
2905+ q . concurrency = 2 ;
2906+ setTimeout ( function ( ) {
2907+ test . equal ( q . running ( ) , 2 ) ;
2908+ q . concurrency = 5 ;
2909+ setTimeout ( function ( ) {
2910+ test . equal ( q . running ( ) , 5 ) ;
2911+ } , 500 ) ;
2912+ } , 500 ) ;
2913+ } , 500 ) ;
29342914} ,
29352915
29362916'push without callback' : function ( test ) {
0 commit comments