3
3
const common = require ( '../common' ) ;
4
4
const http = require ( 'http' ) ;
5
5
const assert = require ( 'assert' ) ;
6
+ const Countdown = require ( '../common/countdown' ) ;
6
7
7
8
// Test that certain response header fields do not repeat.
8
9
// 'content-length' should also be in this list but it is
@@ -27,6 +28,7 @@ const norepeat = [
27
28
'age' ,
28
29
'expires'
29
30
] ;
31
+ const runCount = 2 ;
30
32
31
33
const server = http . createServer ( function ( req , res ) {
32
34
const num = req . headers [ 'x-num' ] ;
@@ -47,8 +49,8 @@ const server = http.createServer(function(req, res) {
47
49
} ) ;
48
50
49
51
server . 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 ++ ) {
52
54
// this runs twice, the first time, the server will use
53
55
// setHeader, the second time it uses writeHead. The
54
56
// result on the client side should be the same in
@@ -58,7 +60,7 @@ server.listen(0, common.mustCall(function() {
58
60
http . get (
59
61
{ port : this . address ( ) . port , headers : { 'x-num' : n } } ,
60
62
common . mustCall ( function ( res ) {
61
- if ( ++ count === 2 ) server . close ( ) ;
63
+ countdown . dec ( ) ;
62
64
for ( const name of norepeat ) {
63
65
assert . strictEqual ( res . headers [ name ] , 'A' ) ;
64
66
}
0 commit comments