From 4b0c8d756f1a9a5cefa36fabd4638bfe3a18372e Mon Sep 17 00:00:00 2001 From: Trivikram Kamat Date: Mon, 25 Sep 2017 20:19:22 -0700 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- ...-http2-server-destroy-before-additional.js | 39 --------------- ...st-http2-server-destroy-before-priority.js | 40 ---------------- .../test-http2-server-destroy-before-push.js | 39 --------------- ...est-http2-server-destroy-before-respond.js | 39 --------------- .../test-http2-server-destroy-before-rst.js | 40 ---------------- .../test-http2-server-destroy-before-state.js | 36 -------------- .../test-http2-server-destroy-before-write.js | 39 --------------- ...est-http2-server-stream-session-destroy.js | 47 +++++++++++++++++++ 8 files changed, 47 insertions(+), 272 deletions(-) delete mode 100644 test/parallel/test-http2-server-destroy-before-additional.js delete mode 100644 test/parallel/test-http2-server-destroy-before-priority.js delete mode 100644 test/parallel/test-http2-server-destroy-before-push.js delete mode 100644 test/parallel/test-http2-server-destroy-before-respond.js delete mode 100644 test/parallel/test-http2-server-destroy-before-rst.js delete mode 100644 test/parallel/test-http2-server-destroy-before-state.js delete mode 100644 test/parallel/test-http2-server-destroy-before-write.js create mode 100644 test/parallel/test-http2-server-stream-session-destroy.js diff --git a/test/parallel/test-http2-server-destroy-before-additional.js b/test/parallel/test-http2-server-destroy-before-additional.js deleted file mode 100644 index c05c67d3a3..0000000000 --- a/test/parallel/test-http2-server-destroy-before-additional.js +++ /dev/null @@ -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(); - -})); diff --git a/test/parallel/test-http2-server-destroy-before-priority.js b/test/parallel/test-http2-server-destroy-before-priority.js deleted file mode 100644 index 20ed2bc558..0000000000 --- a/test/parallel/test-http2-server-destroy-before-priority.js +++ /dev/null @@ -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(); - -})); diff --git a/test/parallel/test-http2-server-destroy-before-push.js b/test/parallel/test-http2-server-destroy-before-push.js deleted file mode 100644 index 65c53b823d..0000000000 --- a/test/parallel/test-http2-server-destroy-before-push.js +++ /dev/null @@ -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(); - -})); diff --git a/test/parallel/test-http2-server-destroy-before-respond.js b/test/parallel/test-http2-server-destroy-before-respond.js deleted file mode 100644 index 4023be431f..0000000000 --- a/test/parallel/test-http2-server-destroy-before-respond.js +++ /dev/null @@ -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(); - -})); diff --git a/test/parallel/test-http2-server-destroy-before-rst.js b/test/parallel/test-http2-server-destroy-before-rst.js deleted file mode 100644 index d067021253..0000000000 --- a/test/parallel/test-http2-server-destroy-before-rst.js +++ /dev/null @@ -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(); - -})); diff --git a/test/parallel/test-http2-server-destroy-before-state.js b/test/parallel/test-http2-server-destroy-before-state.js deleted file mode 100644 index b8ef65fb50..0000000000 --- a/test/parallel/test-http2-server-destroy-before-state.js +++ /dev/null @@ -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(); - -})); diff --git a/test/parallel/test-http2-server-destroy-before-write.js b/test/parallel/test-http2-server-destroy-before-write.js deleted file mode 100644 index 911fe015a7..0000000000 --- a/test/parallel/test-http2-server-destroy-before-write.js +++ /dev/null @@ -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(); - -})); diff --git a/test/parallel/test-http2-server-stream-session-destroy.js b/test/parallel/test-http2-server-stream-session-destroy.js new file mode 100644 index 0000000000..2426216580 --- /dev/null +++ b/test/parallel/test-http2-server-stream-session-destroy.js @@ -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())); + }) +);