diff options
author | James M Snell <jasnell@gmail.com> | 2017-11-15 10:55:31 -0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-11-21 12:47:54 +0100 |
commit | 69e6c5a212622ec15b8c2cf904480b6582c6c3a5 (patch) | |
tree | a6368dc8e37112d82ceb8b4dff6120b4bf027429 /test/parallel/test-http2-ping.js | |
parent | 2ba93f6ed7c96684ed7aeaa32db59ae8e5885f03 (diff) | |
download | android-node-v8-69e6c5a212622ec15b8c2cf904480b6582c6c3a5.tar.gz android-node-v8-69e6c5a212622ec15b8c2cf904480b6582c6c3a5.tar.bz2 android-node-v8-69e6c5a212622ec15b8c2cf904480b6582c6c3a5.zip |
http2: major update to internals
This update does several significant things:
1. It eliminates the base Nghttp2* classes and folds those
in to node::http2::Http2Session and node::http2::Http2Stream
2. It makes node::http2::Http2Stream a StreamBase instance and
sends that out to JS-land to act as the [kHandle] for the
JavaScript Http2Stream class.
3. It shifts some of the callbacks from C++ off of the JavaScript
Http2Session class to the Http2Stream class.
4. It refactors the data provider structure for FD and Stream
based sending to help encapsulate those functions easier
5. It streamlines some of the functions at the C++ layer to
eliminate now unnecessary redirections
6. It cleans up node_http2.cc for better readability and
maintainability
7. It refactors some of the debug output
8. Because Http2Stream instances are now StreamBases, they are
now also trackable using async-hooks
9. The Stream::OnRead algorithm has been simplified with a
couple bugs fixed.
10. I've eliminated node_http2_core.h and node_http2_core-inl.h
11. Detect invalid handshake a report protocol error to session
12. Refactor out of memory error, improve other errors
13. Add Http2Session.prototype.ping
PR-URL: https://github.com/nodejs/node/pull/17105
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sebastiaan Deckers <sebdeckers83@gmail.com>
Diffstat (limited to 'test/parallel/test-http2-ping.js')
-rw-r--r-- | test/parallel/test-http2-ping.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/parallel/test-http2-ping.js b/test/parallel/test-http2-ping.js new file mode 100644 index 0000000000..4892d67b4d --- /dev/null +++ b/test/parallel/test-http2-ping.js @@ -0,0 +1,87 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +const async_hooks = require('async_hooks'); +const assert = require('assert'); +const http2 = require('http2'); + +const pings = new Set(); +const events = [0, 0, 0, 0]; + +const hook = async_hooks.createHook({ + init(id, type, trigger, resource) { + if (type === 'HTTP2PING') { + pings.add(id); + events[0]++; + } + }, + before(id) { + if (pings.has(id)) { + events[1]++; + } + }, + after(id) { + if (pings.has(id)) { + events[2]++; + } + }, + destroy(id) { + if (pings.has(id)) { + events[3]++; + } + } +}); +hook.enable(); + +process.on('exit', () => { + assert.deepStrictEqual(events, [4, 4, 4, 4]); +}); + +const server = http2.createServer(); +server.on('stream', common.mustCall((stream) => { + assert(stream.session.ping(common.mustCall((err, duration, ret) => { + assert.strictEqual(err, null); + assert.strictEqual(typeof duration, 'number'); + assert.strictEqual(ret.length, 8); + stream.end('ok'); + }))); + stream.respond(); +})); + +server.listen(0, common.mustCall(() => { + const client = http2.connect(`http://localhost:${server.address().port}`, + { maxOutstandingPings: 2 }); + client.on('connect', common.mustCall(() => { + { + const payload = Buffer.from('abcdefgh'); + assert(client.ping(payload, common.mustCall((err, duration, ret) => { + assert.strictEqual(err, null); + assert.strictEqual(typeof duration, 'number'); + assert.deepStrictEqual(payload, ret); + }))); + } + { + const payload = Buffer.from('abcdefgi'); + assert(client.ping(payload, common.mustCall((err, duration, ret) => { + assert.strictEqual(err, null); + assert.strictEqual(typeof duration, 'number'); + assert.deepStrictEqual(payload, ret); + }))); + } + // Only max 2 pings at a time based on the maxOutstandingPings option + assert(!client.ping(common.expectsError({ + code: 'ERR_HTTP2_PING_CANCEL', + type: Error, + message: 'HTTP2 ping cancelled' + }))); + const req = client.request(); + req.resume(); + req.on('end', common.mustCall(() => { + client.destroy(); + server.close(); + })); + })); +})); |