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: 16b59cbcFixes: #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
Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,30 @@
11
'use strict';
2-
varassert=require('assert');
3-
varcommon=require('../common');
4-
varhttp=require('http');
2+
constassert=require('assert');
3+
constcommon=require('../common');
4+
consthttp=require('http');
55

66
varstart;
7-
varserver=http.createServer(function(req,res){
7+
constserver=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-
varinterval_id=setInterval(function(){
18-
start=newDate();
19-
if(start.getMilliseconds()>100)
20-
return;
21-
22-
console.log(start.toISOString());
23-
varreq=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=newDate();
18+
constreq=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-
varend=newDate();
37-
console.log(end.toISOString());
38-
assert.equal(start.getSeconds(),end.getSeconds());
39-
assert(end.getMilliseconds()<900);
40-
console.log('ok');
28+
constend=newDate();
29+
assert(end-start<1000,'Entire test should take less than one second');
4130
});

0 commit comments

Comments
(0)