diff options
author | Rich Trott <rtrott@gmail.com> | 2016-12-15 13:31:36 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-12-18 20:58:43 -0800 |
commit | 348e69c89de658d1ea2b386f4166370214c25e95 (patch) | |
tree | 6248096c0a835e6df715dd80b72896ff0f081018 /test/parallel/test-http-client-timeout-event.js | |
parent | 0d3ac89ff7e8e664bd0d09dc8de56f302cbc9ee0 (diff) | |
download | node-new-348e69c89de658d1ea2b386f4166370214c25e95.tar.gz |
test: fix flaky test-http-client-timeout-event
Race condition caused occasional failure on CI. Chained callbacks used
to remove race condition.
PR-URL: https://github.com/nodejs/node/pull/10293
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-http-client-timeout-event.js')
-rw-r--r-- | test/parallel/test-http-client-timeout-event.js | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/test/parallel/test-http-client-timeout-event.js b/test/parallel/test-http-client-timeout-event.js index 8e3d034c31..623b253a20 100644 --- a/test/parallel/test-http-client-timeout-event.js +++ b/test/parallel/test-http-client-timeout-event.js @@ -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); + }); + })); }); |