test: refactored http test to use countdown
PR-URL: https://github.com/nodejs/node/pull/17241 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
7dc24062fc
commit
cd625e0658
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
const Countdown = require('../common/countdown');
|
||||||
|
|
||||||
// Make sure that throwing in 'end' handler doesn't lock
|
// Make sure that throwing in 'end' handler doesn't lock
|
||||||
// up the socket forever.
|
// up the socket forever.
|
||||||
@ -29,10 +30,10 @@ const common = require('../common');
|
|||||||
// the same, we should not be so brittle and easily broken.
|
// the same, we should not be so brittle and easily broken.
|
||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
const countdown = new Countdown(10, () => server.close());
|
||||||
|
|
||||||
let n = 0;
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
if (++n === 10) server.close();
|
countdown.dec();
|
||||||
res.end('ok');
|
res.end('ok');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user