@@ -3,8 +3,7 @@ require('../common');
33const assert = require ( 'assert' ) ;
44const http = require ( 'http' ) ;
55const net = require ( 'net' ) ;
6-
7- let testsComplete = 0 ;
6+ const Countdown = require ( '../common/countdown' ) ;
87
98const testCases = [
109 { path : '/200' , statusMessage : 'OK' ,
@@ -38,6 +37,8 @@ const server = net.createServer(function(connection) {
3837 } ) ;
3938} ) ;
4039
40+ const countdown = new Countdown ( testCases . length , ( ) => server . close ( ) ) ;
41+
4142function runTest ( testCaseIndex ) {
4243 const testCase = testCases [ testCaseIndex ] ;
4344
@@ -50,12 +51,9 @@ function runTest(testCaseIndex) {
5051 assert . strictEqual ( testCase . statusMessage , response . statusMessage ) ;
5152
5253 response . on ( 'end' , function ( ) {
53- testsComplete ++ ;
54-
54+ countdown . dec ( ) ;
5555 if ( testCaseIndex + 1 < testCases . length ) {
5656 runTest ( testCaseIndex + 1 ) ;
57- } else {
58- server . close ( ) ;
5957 }
6058 } ) ;
6159
@@ -64,7 +62,3 @@ function runTest(testCaseIndex) {
6462}
6563
6664server . listen ( 0 , function ( ) { runTest ( 0 ) ; } ) ;
67-
68- process . on ( 'exit' , function ( ) {
69- assert . strictEqual ( testCases . length , testsComplete ) ;
70- } ) ;
0 commit comments