Skip to content

Commit 8a26ba1

Browse files
TrottMylesBorins
authored andcommitted
test: fix flaky test-https-timeout
Remove `setTimeout()` in test and instead rely on `common.mustCall()` on a `timeout` event handler. The test was flaky on CI. The flakiness was replicable by running the test under load. This version, in contrast, is robust under load. Took the opportunity to do some `var` -> `const` while refactoring. PR-URL: #10404 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Italo A. Casas <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent eeb2d78 commit 8a26ba1

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
'use strict';
2-
varcommon=require('../common');
2+
constcommon=require('../common');
33

44
if(!common.hasCrypto){
55
common.skip('missing crypto');
66
return;
77
}
8-
varhttps=require('https');
8+
consthttps=require('https');
99

10-
varfs=require('fs');
10+
constfs=require('fs');
1111

12-
varoptions={
12+
constoptions={
1313
key: fs.readFileSync(common.fixturesDir+'/keys/agent1-key.pem'),
1414
cert: fs.readFileSync(common.fixturesDir+'/keys/agent1-cert.pem')
1515
};
1616

1717
// a server that never replies
18-
varserver=https.createServer(options,function(){
18+
constserver=https.createServer(options,function(){
1919
console.log('Got request. Doing nothing.');
20-
}).listen(0,function(){
21-
varreq=https.request({
20+
}).listen(0,common.mustCall(function(){
21+
constreq=https.request({
2222
host: 'localhost',
2323
port: this.address().port,
2424
path: '/',
@@ -28,26 +28,14 @@ var server = https.createServer(options, function(){
2828
req.setTimeout(10);
2929
req.end();
3030

31-
req.on('response',function(res){
31+
req.on('response',function(){
3232
console.log('got response');
3333
});
3434

35-
req.on('socket',function(){
36-
console.log('got a socket');
37-
38-
req.socket.on('connect',function(){
39-
console.log('socket connected');
40-
});
41-
42-
setTimeout(function(){
43-
thrownewError('Did not get timeout event');
44-
},200);
45-
});
46-
47-
req.on('timeout',function(){
35+
req.on('timeout',common.mustCall(function(){
4836
console.log('timeout occurred outside');
4937
req.destroy();
5038
server.close();
5139
process.exit(0);
52-
});
53-
});
40+
}));
41+
}));

0 commit comments

Comments
(0)