@@ -24,8 +24,7 @@ require('../common');
24
24
const assert = require ( 'assert' ) ;
25
25
const http = require ( 'http' ) ;
26
26
const net = require ( 'net' ) ;
27
-
28
- let testsComplete = 0 ;
27
+ const Countdown = require ( '../common/countdown' ) ;
29
28
30
29
const testCases = [
31
30
{ path : '/200' , statusMessage : 'OK' ,
@@ -59,6 +58,8 @@ const server = net.createServer(function(connection) {
59
58
} ) ;
60
59
} ) ;
61
60
61
+ const countdown = new Countdown ( testCases . length , ( ) => server . close ( ) ) ;
62
+
62
63
function runTest ( testCaseIndex ) {
63
64
const testCase = testCases [ testCaseIndex ] ;
64
65
@@ -71,12 +72,9 @@ function runTest(testCaseIndex) {
71
72
assert . strictEqual ( testCase . statusMessage , response . statusMessage ) ;
72
73
73
74
response . on ( 'end' , function ( ) {
74
- testsComplete ++ ;
75
-
75
+ countdown . dec ( ) ;
76
76
if ( testCaseIndex + 1 < testCases . length ) {
77
77
runTest ( testCaseIndex + 1 ) ;
78
- } else {
79
- server . close ( ) ;
80
78
}
81
79
} ) ;
82
80
@@ -85,7 +83,3 @@ function runTest(testCaseIndex) {
85
83
}
86
84
87
85
server . listen ( 0 , function ( ) { runTest ( 0 ) ; } ) ;
88
-
89
- process . on ( 'exit' , function ( ) {
90
- assert . strictEqual ( testCases . length , testsComplete ) ;
91
- } ) ;
0 commit comments