Skip to content

Commit bdb535c

Browse files
sreepurnajastiMylesBorins
authored andcommitted
test: Use countdown in test file
Fixes: #17169 PR-URL: #17646 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 31c5db6 commit bdb535c

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed
+6-19
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,27 @@
11
'use strict';
22
require('../common');
3-
const assert = require('assert');
43
const http = require('http');
54
const net = require('net');
5+
const Countdown = require('../common/countdown');
66

77
const big = Buffer.alloc(16 * 1024, 'A');
88

99
const COUNT = 1e4;
1010

11-
let received = 0;
11+
const countdown = new Countdown(COUNT, () => {
12+
server.close();
13+
client.end();
14+
});
1215

1316
let client;
1417
const server = http.createServer(function(req, res) {
1518
res.end(big, function() {
16-
if (++received === COUNT) {
17-
server.close();
18-
client.end();
19-
}
19+
countdown.dec();
2020
});
2121
}).listen(0, function() {
2222
const req = new Array(COUNT + 1).join('GET / HTTP/1.1\r\n\r\n');
2323
client = net.connect(this.address().port, function() {
2424
client.write(req);
2525
});
26-
27-
// Just let the test terminate instead of hanging
28-
client.on('close', function() {
29-
if (received !== COUNT)
30-
server.close();
31-
});
3226
client.resume();
3327
});
34-
35-
process.on('exit', function() {
36-
// The server should pause connection on pipeline flood, but it shoul still
37-
// resume it and finish processing the requests, when its output queue will
38-
// be empty again.
39-
assert.strictEqual(received, COUNT);
40-
});

0 commit comments

Comments
 (0)