Skip to content

Commit

Permalink
http2: add test for sessionError and aborted, and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rexagod committed Apr 22, 2020
1 parent 05df7f1 commit 046269c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
6 changes: 3 additions & 3 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ The `'session'` event is emitted when a new `Http2Session` is created by the
added: v8.4.0
-->

> Stability: 1 - Experimental. Use [`'aborted'`][].
> Stability: 0 - Deprecated. Use [`'aborted'`][].
The `'sessionError'` event is emitted when an `'error'` event is emitted by
an `Http2Session` object associated with the `Http2Server`.
Expand Down Expand Up @@ -1878,7 +1878,7 @@ The `'session'` event is emitted when a new `Http2Session` is created by the
added: v8.4.0
-->

> Stability: 1 - Experimental. Use [`'aborted'`][].
> Stability: 0 - Deprecated. Use [`'aborted'`][].
The `'sessionError'` event is emitted when an `'error'` event is emitted by
an `Http2Session` object associated with the `Http2SecureServer`.
Expand Down Expand Up @@ -3583,9 +3583,9 @@ following additional properties:
[RFC 8336]: https://tools.ietf.org/html/rfc8336
[RFC 8441]: https://tools.ietf.org/html/rfc8441
[`'checkContinue'`]: #http2_event_checkcontinue
[`'aborted'`]: #http2_event_aborted
[`'connect'`]: #http2_event_connect
[`'request'`]: #http2_event_request
[`'aborted'`]: #http2_event_aborted
[`'unknownProtocol'`]: #http2_event_unknownprotocol
[`ClientHttp2Stream`]: #http2_class_clienthttp2stream
[`Duplex`]: stream.html#stream_class_stream_duplex
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2794,8 +2794,8 @@ function sessionOnPriority(stream, parent, weight, exclusive) {

function sessionOnError(error) {
if (this[kServer] !== undefined) {
this[kServer].emit('sessionError', error, this);
this[kServer].emit('aborted', error, this);
this[kServer].emit('sessionError', error, this);
}
}

Expand Down
22 changes: 11 additions & 11 deletions test/parallel/test-http2-client-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,27 @@ const Countdown = require('../common/countdown');

req.on('response', common.mustNotCall());

const aborted = {
const sessionError = {
name: 'Error',
code: 'ERR_HTTP2_INVALID_SESSION',
message: 'The session has been destroyed'
};

assert.throws(() => client.setNextStreamID(), aborted);
assert.throws(() => client.ping(), aborted);
assert.throws(() => client.settings({}), aborted);
assert.throws(() => client.goaway(), aborted);
assert.throws(() => client.request(), aborted);
assert.throws(() => client.setNextStreamID(), sessionError);
assert.throws(() => client.ping(), sessionError);
assert.throws(() => client.settings({}), sessionError);
assert.throws(() => client.goaway(), sessionError);
assert.throws(() => client.request(), sessionError);
client.close(); // Should be a non-op at this point

// Wait for setImmediate call from destroy() to complete
// so that state.destroyed is set to true
setImmediate(() => {
assert.throws(() => client.setNextStreamID(), aborted);
assert.throws(() => client.ping(), aborted);
assert.throws(() => client.settings({}), aborted);
assert.throws(() => client.goaway(), aborted);
assert.throws(() => client.request(), aborted);
assert.throws(() => client.setNextStreamID(), sessionError);
assert.throws(() => client.ping(), sessionError);
assert.throws(() => client.settings({}), sessionError);
assert.throws(() => client.goaway(), sessionError);
assert.throws(() => client.request(), sessionError);
client.close(); // Should be a non-op at this point
});

Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-http2-emit-on-session-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto) { common.skip('missing crypto'); }
const { strictEqual } = require('assert');
const h2 = require('http2');

const server = h2.createServer();
const _error = new Error('some error');

// Check if `sessionError` and `aborted` events
// are emitted if `session` emits an `error` event
server.on('aborted', common.mustCall((error, _ins) => {
strictEqual(error, _error);
}));

server.on('sessionError', common.mustCall((error, _ins) => {
strictEqual(error, _error);
}));

server.on('session', common.mustCall((session) => {
session.destroy(_error);
server.close();
}));

server.listen(0, common.mustCall(() => {
const session = h2.connect(`http://localhost:${server.address().port}`);
session.close();
}));

0 comments on commit 046269c

Please sign in to comment.