33const common = require ( '../common' ) ;
44const http = require ( 'http' ) ;
55const assert = require ( 'assert' ) ;
6+ const Countdown = require ( '../common/countdown' ) ;
67
78// Test that certain response header fields do not repeat.
89// 'content-length' should also be in this list but it is
@@ -27,6 +28,7 @@ const norepeat = [
2728 'age' ,
2829 'expires'
2930] ;
31+ const runCount = 2 ;
3032
3133const server = http . createServer ( function ( req , res ) {
3234 const num = req . headers [ 'x-num' ] ;
@@ -47,8 +49,8 @@ const server = http.createServer(function(req, res) {
4749} ) ;
4850
4951server . listen ( 0 , common . mustCall ( function ( ) {
50- let count = 0 ;
51- for ( let n = 1 ; n <= 2 ; n ++ ) {
52+ const countdown = new Countdown ( runCount , ( ) => server . close ( ) ) ;
53+ for ( let n = 1 ; n <= runCount ; n ++ ) {
5254 // this runs twice, the first time, the server will use
5355 // setHeader, the second time it uses writeHead. The
5456 // result on the client side should be the same in
@@ -58,7 +60,7 @@ server.listen(0, common.mustCall(function() {
5860 http . get (
5961 { port : this . address ( ) . port , headers : { 'x-num' : n } } ,
6062 common . mustCall ( function ( res ) {
61- if ( ++ count === 2 ) server . close ( ) ;
63+ countdown . dec ( ) ;
6264 for ( const name of norepeat ) {
6365 assert . strictEqual ( res . headers [ name ] , 'A' ) ;
6466 }
0 commit comments