Skip to content

Commit be41eb7

Browse files
Trottrvagg
authored andcommitted
test: refactor test-http-exit-delay
test-http-exit-delay was introduced to confirm the removal of a 1 second delay that can occur when exiting node after an http request. This change refactors the test for simplicity and also in the hopes of either eliminating flakiness on CI or, if not that, at least making the source of the flakiness easier to track down. Ref: 16b59cbc Fixes: #4045 PR-URL: #4055 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 756ab9c commit be41eb7

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

test/parallel/test-http-exit-delay.js

+17-28
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,30 @@
11
'use strict';
2-
var assert = require('assert');
3-
var common = require('../common');
4-
var http = require('http');
2+
const assert = require('assert');
3+
const common = require('../common');
4+
const http = require('http');
55

66
var start;
7-
var server = http.createServer(function(req, res) {
7+
const server = http.createServer(common.mustCall(function(req, res) {
88
req.resume();
99
req.on('end', function() {
1010
res.end('Success');
1111
});
1212

1313
server.close();
14-
});
15-
16-
server.listen(common.PORT, 'localhost', function() {
17-
var interval_id = setInterval(function() {
18-
start = new Date();
19-
if (start.getMilliseconds() > 100)
20-
return;
21-
22-
console.log(start.toISOString());
23-
var req = http.request({
24-
'host': 'localhost',
25-
'port': common.PORT,
26-
'agent': false,
27-
'method': 'PUT'
28-
});
14+
}));
2915

30-
req.end('Test');
31-
clearInterval(interval_id);
32-
}, 10);
33-
});
16+
server.listen(common.PORT, 'localhost', common.mustCall(function() {
17+
start = new Date();
18+
const req = http.request({
19+
'host': 'localhost',
20+
'port': common.PORT,
21+
'agent': false,
22+
'method': 'PUT'
23+
});
24+
req.end('Test');
25+
}));
3426

3527
process.on('exit', function() {
36-
var end = new Date();
37-
console.log(end.toISOString());
38-
assert.equal(start.getSeconds(), end.getSeconds());
39-
assert(end.getMilliseconds() < 900);
40-
console.log('ok');
28+
const end = new Date();
29+
assert(end - start < 1000, 'Entire test should take less than one second');
4130
});

0 commit comments

Comments
 (0)