@@ -30,6 +30,12 @@ var HEIGHT = 500;
3030// minimum satisfactory file size [in bytes]
3131var MIN_SIZE = 100 ;
3232
33+ // wait time between each test batch
34+ var BATCH_WAIT = 500 ;
35+
36+ // number of tests in each test batch
37+ var BATCH_SIZE = 5 ;
38+
3339/**
3440 * Image export test script.
3541 *
@@ -65,21 +71,39 @@ if(mockList.length === 0) {
6571runInBatch ( mockList ) ;
6672
6773function runInBatch ( mockList ) {
74+ var running = 0 ;
75+
6876 test ( 'testing image export formats' , function ( t ) {
6977 t . plan ( mockList . length * FORMATS . length ) ;
7078
71- // send all requests out at once
72- mockList . forEach ( function ( mockName ) {
73- FORMATS . forEach ( function ( format ) {
74- testExport ( mockName , format , t ) ;
75- } ) ;
76- } ) ;
79+ for ( var i = 0 ; i < mockList . length ; i ++ ) {
80+ for ( var j = 0 ; j < FORMATS . length ; j ++ ) {
81+ run ( mockList [ i ] , FORMATS [ j ] , t ) ;
82+ }
83+ }
7784 } ) ;
85+
86+ function run ( mockName , format , t ) {
87+ if ( running >= BATCH_SIZE ) {
88+ setTimeout ( function ( ) {
89+ run ( mockName , format , t ) ;
90+ } , BATCH_WAIT ) ;
91+ return ;
92+ }
93+ running ++ ;
94+
95+ // throttle the number of tests running concurrently
96+
97+ testExport ( mockName , format , function ( didExport , mockName , format ) {
98+ running -- ;
99+ t . ok ( didExport , mockName + ' should be properly exported as a ' + format ) ;
100+ } ) ;
101+ }
78102}
79103
80104// The tests below determine whether the images are properly
81105// exported by (only) checking the file size of the generated images.
82- function testExport ( mockName , format , t ) {
106+ function testExport ( mockName , format , cb ) {
83107 var specs = {
84108 mockName : mockName ,
85109 format : format ,
@@ -105,7 +129,7 @@ function testExport(mockName, format, t) {
105129 didExport = stats . size > MIN_SIZE ;
106130 }
107131
108- t . ok ( didExport , mockName + ' should be properly exported as a ' + format ) ;
132+ cb ( didExport , mockName , format ) ;
109133 }
110134
111135 request ( requestOpts )
0 commit comments