-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
94fd8f3
commit 293d223
Showing
1 changed file
with
10 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
var options = { | ||
const options = { | ||
method: 'GET', | ||
port: undefined, | ||
host: '127.0.0.1', | ||
path: '/' | ||
}; | ||
|
||
var server = http.createServer(); | ||
const server = http.createServer(); | ||
|
||
server.listen(0, options.host, function() { | ||
options.port = this.address().port; | ||
var req = http.request(options); | ||
const req = http.request(options); | ||
req.on('error', function() { | ||
// this space is intentionally left blank | ||
}); | ||
req.on('close', common.mustCall(() => server.close())); | ||
|
||
var timeout_events = 0; | ||
req.setTimeout(1); | ||
req.on('timeout', common.mustCall(() => timeout_events += 1)); | ||
setTimeout(function() { | ||
req.destroy(); | ||
assert.strictEqual(timeout_events, 1); | ||
}, common.platformTimeout(100)); | ||
setTimeout(function() { | ||
req.end(); | ||
}, common.platformTimeout(50)); | ||
req.on('timeout', common.mustCall(() => { | ||
req.end(() => { | ||
setTimeout(() => { | ||
req.destroy(); | ||
}, 100); | ||
}); | ||
})); | ||
}); |