summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-compat-serverresponse-destroy.js
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2017-09-01 15:20:30 -0400
committerRuben Bridgewater <ruben@bridgewater.de>2017-09-03 20:18:49 -0300
commit198fcb9c620a0f08969d042f763cb491cb1c57d6 (patch)
tree5be09d9a23d7a7000cb0c543d23bcdb69b698135 /test/parallel/test-http2-compat-serverresponse-destroy.js
parent233d1e276a481bcee5c506d09041f4a667ea227d (diff)
downloadandroid-node-v8-198fcb9c620a0f08969d042f763cb491cb1c57d6.tar.gz
android-node-v8-198fcb9c620a0f08969d042f763cb491cb1c57d6.tar.bz2
android-node-v8-198fcb9c620a0f08969d042f763cb491cb1c57d6.zip
test: increase Http2ServerResponse test coverage
Modify existing header tests for Http2ServerResponse to include sendDate (get and set) and headersSent. Expand existing test for end to include a check for closed. Add a new test for destroy. PR-URL: https://github.com/nodejs/node/pull/15074 Refs: https://github.com/nodejs/node/issues/14985 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-http2-compat-serverresponse-destroy.js')
-rw-r--r--test/parallel/test-http2-compat-serverresponse-destroy.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/parallel/test-http2-compat-serverresponse-destroy.js b/test/parallel/test-http2-compat-serverresponse-destroy.js
new file mode 100644
index 0000000000..40c73b0887
--- /dev/null
+++ b/test/parallel/test-http2-compat-serverresponse-destroy.js
@@ -0,0 +1,91 @@
+// Flags: --expose-http2
+'use strict';
+
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+const assert = require('assert');
+const http2 = require('http2');
+
+// Check that destroying the Http2ServerResponse stream produces
+// the expected result, including the ability to throw an error
+// which is emitted on server.streamError
+
+const errors = [
+ 'test-error',
+ Error('test')
+];
+let nextError;
+
+const server = http2.createServer(common.mustCall((req, res) => {
+ req.on('error', common.mustNotCall());
+ res.on('error', common.mustNotCall());
+
+ res.on('finish', common.mustCall(() => {
+ assert.doesNotThrow(() => res.destroy(nextError));
+ assert.strictEqual(res.closed, true);
+ }));
+
+ if (req.path !== '/') {
+ nextError = errors.shift();
+ }
+ res.destroy(nextError);
+}, 3));
+
+server.on(
+ 'streamError',
+ common.mustCall((err) => assert.strictEqual(err, nextError), 2)
+);
+
+server.listen(0, common.mustCall(() => {
+ const port = server.address().port;
+ const client = http2.connect(`http://localhost:${port}`);
+ const req = client.request({
+ ':path': '/',
+ ':method': 'GET',
+ ':scheme': 'http',
+ ':authority': `localhost:${port}`
+ });
+
+ req.on('response', common.mustNotCall());
+ req.on('error', common.mustNotCall());
+ req.on('end', common.mustCall());
+
+ req.resume();
+ req.end();
+
+ const req2 = client.request({
+ ':path': '/error',
+ ':method': 'GET',
+ ':scheme': 'http',
+ ':authority': `localhost:${port}`
+ });
+
+ req2.on('response', common.mustNotCall());
+ req2.on('error', common.mustNotCall());
+ req2.on('end', common.mustCall());
+
+ req2.resume();
+ req2.end();
+
+ const req3 = client.request({
+ ':path': '/error',
+ ':method': 'GET',
+ ':scheme': 'http',
+ ':authority': `localhost:${port}`
+ });
+
+ req3.on('response', common.mustNotCall());
+ req3.on('error', common.expectsError({
+ code: 'ERR_HTTP2_STREAM_ERROR',
+ type: Error,
+ message: 'Stream closed with error code 2'
+ }));
+ req3.on('end', common.mustCall(() => {
+ server.close();
+ client.destroy();
+ }));
+
+ req3.resume();
+ req3.end();
+}));