diff options
author | Rich Trott <rtrott@gmail.com> | 2018-12-06 10:34:19 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-12-08 12:35:57 -0800 |
commit | 9df18ad7c36e7bef6334a28f4002cf6e64586a97 (patch) | |
tree | 8791e799e90099ecd87471c98bc656cc25266b52 /test/parallel/test-http2-session-timeout.js | |
parent | 3fe00effe0d1905486472ed82f7716321d6ac8e1 (diff) | |
download | android-node-v8-9df18ad7c36e7bef6334a28f4002cf6e64586a97.tar.gz android-node-v8-9df18ad7c36e7bef6334a28f4002cf6e64586a97.tar.bz2 android-node-v8-9df18ad7c36e7bef6334a28f4002cf6e64586a97.zip |
test: move http2 test to parallel
A fix to test-http2-session-timeout makes it sufficiently robust that it
can be moved to the parallel directory.
PR-URL: https://github.com/nodejs/node/pull/24877
Fixes: https://github.com/https://github.com/nodejs/node/issues/20628
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test/parallel/test-http2-session-timeout.js')
-rw-r--r-- | test/parallel/test-http2-session-timeout.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/parallel/test-http2-session-timeout.js b/test/parallel/test-http2-session-timeout.js new file mode 100644 index 0000000000..0fa6a2c13c --- /dev/null +++ b/test/parallel/test-http2-session-timeout.js @@ -0,0 +1,62 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); +const assert = require('assert'); +const http2 = require('http2'); + +let requests = 0; +const mustNotCall = () => { + assert.fail(`Timeout after ${requests} request(s)`); +}; + +const server = http2.createServer(); +// Disable server timeout until first request. We will set the timeout based on +// how long the first request takes. +server.timeout = 0; + +server.on('request', (req, res) => res.end()); +server.on('timeout', mustNotCall); + +server.listen(0, common.mustCall(() => { + const port = server.address().port; + + const url = `http://localhost:${port}`; + const client = http2.connect(url); + let startTime = process.hrtime(); + makeReq(); + + function makeReq() { + const request = client.request({ + ':path': '/foobar', + ':method': 'GET', + ':scheme': 'http', + ':authority': `localhost:${port}`, + }); + request.resume(); + request.end(); + + requests += 1; + + request.on('end', () => { + const diff = process.hrtime(startTime); + const milliseconds = (diff[0] * 1e3 + diff[1] / 1e6); + if (server.timeout === 0) { + // Set the timeout now. First connection will take significantly longer + // than subsequent connections, so using the duration of the first + // connection as the timeout should be robust. Double it anyway for good + // measure. + server.timeout = milliseconds * 2; + startTime = process.hrtime(); + makeReq(); + } else if (milliseconds < server.timeout * 2) { + makeReq(); + } else { + server.removeListener('timeout', mustNotCall); + server.close(); + client.close(); + } + }); + } +})); |