Skip to content

Commit 348e69c

Browse files
committed
test: fix flaky test-http-client-timeout-event
Race condition caused occasional failure on CI. Chained callbacks used to remove race condition. PR-URL: #10293 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 0d3ac89 commit 348e69c

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
43
const http = require('http');
54

6-
var options = {
5+
const options = {
76
method: 'GET',
87
port: undefined,
98
host: '127.0.0.1',
109
path: '/'
1110
};
1211

13-
var server = http.createServer();
12+
const server = http.createServer();
1413

1514
server.listen(0, options.host, function() {
1615
options.port = this.address().port;
17-
var req = http.request(options);
16+
const req = http.request(options);
1817
req.on('error', function() {
1918
// this space is intentionally left blank
2019
});
2120
req.on('close', common.mustCall(() => server.close()));
2221

23-
var timeout_events = 0;
2422
req.setTimeout(1);
25-
req.on('timeout', common.mustCall(() => timeout_events += 1));
26-
setTimeout(function() {
27-
req.destroy();
28-
assert.strictEqual(timeout_events, 1);
29-
}, common.platformTimeout(100));
30-
setTimeout(function() {
31-
req.end();
32-
}, common.platformTimeout(50));
23+
req.on('timeout', common.mustCall(() => {
24+
req.end(() => {
25+
setTimeout(() => {
26+
req.destroy();
27+
}, 100);
28+
});
29+
}));
3330
});

0 commit comments

Comments
 (0)