test: consolidate http2 tests in one file
PR-URL: https://github.com/nodejs/node/pull/15624 Refs: https://github.com/nodejs/node/issues/14985 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
af6af08482
commit
2adf68035c
@ -1,39 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const h2 = require('http2');
|
||||
|
||||
const server = h2.createServer();
|
||||
|
||||
// we use the lower-level API here
|
||||
server.on('stream', common.mustCall(onStream));
|
||||
|
||||
function onStream(stream, headers, flags) {
|
||||
stream.session.destroy();
|
||||
assert.throws(() => stream.additionalHeaders({}),
|
||||
common.expectsError({
|
||||
code: 'ERR_HTTP2_INVALID_STREAM',
|
||||
message: /^The stream has been destroyed$/
|
||||
}));
|
||||
}
|
||||
|
||||
server.listen(0);
|
||||
|
||||
server.on('listening', common.mustCall(() => {
|
||||
|
||||
const client = h2.connect(`http://localhost:${server.address().port}`);
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
|
||||
req.on('response', common.mustNotCall());
|
||||
req.resume();
|
||||
req.on('end', common.mustCall(() => {
|
||||
server.close();
|
||||
client.destroy();
|
||||
}));
|
||||
req.end();
|
||||
|
||||
}));
|
@ -1,40 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const http2 = require('http2');
|
||||
|
||||
const server = http2.createServer();
|
||||
|
||||
// Test that ERR_HTTP2_INVALID_STREAM is thrown when a stream is destroyed
|
||||
// before calling stream.priority
|
||||
server.on('stream', common.mustCall(onStream));
|
||||
|
||||
function onStream(stream, headers, flags) {
|
||||
stream.session.destroy();
|
||||
assert.throws(() => stream.priority(),
|
||||
common.expectsError({
|
||||
code: 'ERR_HTTP2_INVALID_STREAM',
|
||||
message: /^The stream has been destroyed$/
|
||||
}));
|
||||
}
|
||||
|
||||
server.listen(0);
|
||||
|
||||
server.on('listening', common.mustCall(() => {
|
||||
|
||||
const client = http2.connect(`http://localhost:${server.address().port}`);
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
|
||||
req.on('response', common.mustNotCall());
|
||||
req.resume();
|
||||
req.on('end', common.mustCall(() => {
|
||||
server.close();
|
||||
client.destroy();
|
||||
}));
|
||||
req.end();
|
||||
|
||||
}));
|
@ -1,39 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const h2 = require('http2');
|
||||
|
||||
const server = h2.createServer();
|
||||
|
||||
// we use the lower-level API here
|
||||
server.on('stream', common.mustCall(onStream));
|
||||
|
||||
function onStream(stream, headers, flags) {
|
||||
stream.session.destroy();
|
||||
assert.throws(() => stream.pushStream({}, common.mustNotCall()),
|
||||
common.expectsError({
|
||||
code: 'ERR_HTTP2_INVALID_STREAM',
|
||||
message: /^The stream has been destroyed$/
|
||||
}));
|
||||
}
|
||||
|
||||
server.listen(0);
|
||||
|
||||
server.on('listening', common.mustCall(() => {
|
||||
|
||||
const client = h2.connect(`http://localhost:${server.address().port}`);
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
|
||||
req.on('response', common.mustNotCall());
|
||||
req.resume();
|
||||
req.on('end', common.mustCall(() => {
|
||||
server.close();
|
||||
client.destroy();
|
||||
}));
|
||||
req.end();
|
||||
|
||||
}));
|
@ -1,39 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const h2 = require('http2');
|
||||
|
||||
const server = h2.createServer();
|
||||
|
||||
// we use the lower-level API here
|
||||
server.on('stream', common.mustCall(onStream));
|
||||
|
||||
function onStream(stream, headers, flags) {
|
||||
stream.session.destroy();
|
||||
assert.throws(() => stream.respond({}),
|
||||
common.expectsError({
|
||||
code: 'ERR_HTTP2_INVALID_STREAM',
|
||||
message: /^The stream has been destroyed$/
|
||||
}));
|
||||
}
|
||||
|
||||
server.listen(0);
|
||||
|
||||
server.on('listening', common.mustCall(() => {
|
||||
|
||||
const client = h2.connect(`http://localhost:${server.address().port}`);
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
|
||||
req.on('response', common.mustNotCall());
|
||||
req.resume();
|
||||
req.on('end', common.mustCall(() => {
|
||||
server.close();
|
||||
client.destroy();
|
||||
}));
|
||||
req.end();
|
||||
|
||||
}));
|
@ -1,40 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const http2 = require('http2');
|
||||
|
||||
const server = http2.createServer();
|
||||
|
||||
// Test that ERR_HTTP2_INVALID_STREAM is thrown when a stream is destroyed
|
||||
// before calling stream.rstStream
|
||||
server.on('stream', common.mustCall(onStream));
|
||||
|
||||
function onStream(stream, headers, flags) {
|
||||
stream.session.destroy();
|
||||
assert.throws(() => stream.rstStream(),
|
||||
common.expectsError({
|
||||
code: 'ERR_HTTP2_INVALID_STREAM',
|
||||
message: /^The stream has been destroyed$/
|
||||
}));
|
||||
}
|
||||
|
||||
server.listen(0);
|
||||
|
||||
server.on('listening', common.mustCall(() => {
|
||||
|
||||
const client = http2.connect(`http://localhost:${server.address().port}`);
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
|
||||
req.on('response', common.mustNotCall());
|
||||
req.resume();
|
||||
req.on('end', common.mustCall(() => {
|
||||
server.close();
|
||||
client.destroy();
|
||||
}));
|
||||
req.end();
|
||||
|
||||
}));
|
@ -1,36 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const http2 = require('http2');
|
||||
|
||||
const server = http2.createServer();
|
||||
|
||||
// Test that stream.state getter returns and empty object
|
||||
// if the stream session has been destroyed
|
||||
server.on('stream', common.mustCall(onStream));
|
||||
|
||||
function onStream(stream, headers, flags) {
|
||||
stream.session.destroy();
|
||||
assert.deepStrictEqual(Object.create(null), stream.state);
|
||||
}
|
||||
|
||||
server.listen(0);
|
||||
|
||||
server.on('listening', common.mustCall(() => {
|
||||
|
||||
const client = http2.connect(`http://localhost:${server.address().port}`);
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
|
||||
req.on('response', common.mustNotCall());
|
||||
req.resume();
|
||||
req.on('end', common.mustCall(() => {
|
||||
server.close();
|
||||
client.destroy();
|
||||
}));
|
||||
req.end();
|
||||
|
||||
}));
|
@ -1,39 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const h2 = require('http2');
|
||||
|
||||
const server = h2.createServer();
|
||||
|
||||
// we use the lower-level API here
|
||||
server.on('stream', common.mustCall(onStream));
|
||||
|
||||
function onStream(stream, headers, flags) {
|
||||
stream.session.destroy();
|
||||
assert.throws(() => stream.write('data'),
|
||||
common.expectsError({
|
||||
code: 'ERR_HTTP2_INVALID_STREAM',
|
||||
type: Error
|
||||
}));
|
||||
}
|
||||
|
||||
server.listen(0);
|
||||
|
||||
server.on('listening', common.mustCall(() => {
|
||||
|
||||
const client = h2.connect(`http://localhost:${server.address().port}`);
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
|
||||
req.on('response', common.mustNotCall());
|
||||
req.resume();
|
||||
req.on('end', common.mustCall(() => {
|
||||
server.close();
|
||||
client.destroy();
|
||||
}));
|
||||
req.end();
|
||||
|
||||
}));
|
47
test/parallel/test-http2-server-stream-session-destroy.js
Normal file
47
test/parallel/test-http2-server-stream-session-destroy.js
Normal file
@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
const assert = require('assert');
|
||||
const h2 = require('http2');
|
||||
|
||||
const server = h2.createServer();
|
||||
|
||||
server.on(
|
||||
'stream',
|
||||
common.mustCall((stream) => {
|
||||
const errorObj = {
|
||||
type: Error,
|
||||
code: 'ERR_HTTP2_INVALID_STREAM',
|
||||
message: 'The stream has been destroyed'
|
||||
};
|
||||
stream.session.destroy();
|
||||
|
||||
// Test that stream.state getter returns an empty object
|
||||
// when the stream session has been destroyed
|
||||
assert.deepStrictEqual(Object.create(null), stream.state);
|
||||
|
||||
// Test that ERR_HTTP2_INVALID_STREAM is thrown while calling
|
||||
// stream operations after the stream session has been destroyed
|
||||
common.expectsError(() => stream.additionalHeaders(), errorObj);
|
||||
common.expectsError(() => stream.priority(), errorObj);
|
||||
common.expectsError(
|
||||
() => stream.pushStream({}, common.mustNotCall()),
|
||||
errorObj
|
||||
);
|
||||
common.expectsError(() => stream.respond(), errorObj);
|
||||
common.expectsError(() => stream.rstStream(), errorObj);
|
||||
common.expectsError(() => stream.write('data'), errorObj);
|
||||
})
|
||||
);
|
||||
|
||||
server.listen(
|
||||
0,
|
||||
common.mustCall(() => {
|
||||
const client = h2.connect(`http://localhost:${server.address().port}`);
|
||||
const req = client.request();
|
||||
req.resume();
|
||||
req.on('end', common.mustCall(() => server.close()));
|
||||
})
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user