@@ -12,6 +12,7 @@ var gm = require('gm');
12
12
var TOLERANCE = 1e-6 ; // pixel comparison tolerance
13
13
var BASE_TIMEOUT = 500 ; // base timeout time
14
14
var BATCH_SIZE = 5 ; // size of each test 'batch'
15
+ var running = 0 ; // number of tests currently running
15
16
16
17
var touch = function ( fileName ) {
17
18
fs . closeSync ( fs . openSync ( fileName , 'w' ) ) ;
@@ -53,17 +54,10 @@ function runAll() {
53
54
) ;
54
55
} ) ;
55
56
56
- var cnt = 0 ;
57
-
58
- function testFunction ( ) {
59
- testMock ( mocks [ cnt ++ ] , t ) ;
60
- }
61
-
62
57
t . plan ( mocks . length ) ;
63
58
64
59
for ( var i = 0 ; i < mocks . length ; i ++ ) {
65
- setTimeout ( testFunction ,
66
- BASE_TIMEOUT * Math . floor ( i / BATCH_SIZE ) * BATCH_SIZE ) ;
60
+ testMock ( mocks [ i ] , t ) ;
67
61
}
68
62
69
63
} ) ;
@@ -77,6 +71,13 @@ function runSingle(userFileName) {
77
71
}
78
72
79
73
function testMock ( fileName , t ) {
74
+ // throttle the number of tests running concurrently
75
+ if ( running >= BATCH_SIZE ) {
76
+ setTimeout ( function ( ) { testMock ( fileName , t ) ; } , BASE_TIMEOUT ) ;
77
+ return ;
78
+ }
79
+ running ++ ;
80
+
80
81
var figure = require ( path . join ( constants . pathToTestImageMocks , fileName ) ) ;
81
82
var bodyMock = {
82
83
figure : figure ,
@@ -91,6 +92,8 @@ function testMock(fileName, t) {
91
92
var options = getOptions ( bodyMock , 'http://localhost:9010/' ) ;
92
93
93
94
function checkImage ( ) {
95
+ running -- ;
96
+
94
97
var options = {
95
98
file : diffPath ,
96
99
highlightColor : 'purple' ,
0 commit comments