summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrivikram <16024985+trivikr@users.noreply.github.com>2018-02-18 13:39:06 -0800
committerMyles Borins <mylesborins@google.com>2018-08-16 01:59:15 -0400
commit4b4383918f550caef88fe03787dc8d0a17651238 (patch)
treeb35d263e206fb1000de6406f94856e0c37c20898 /test
parent814021182e9e5ea89d17feb8fd4bdfbc4a0d2626 (diff)
downloadnode-new-4b4383918f550caef88fe03787dc8d0a17651238.tar.gz
test: http2 compat response.write() error checks
PR-URL: https://github.com/nodejs/node/pull/18859 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http2-compat-serverresponse-write-no-cb.js95
-rw-r--r--test/parallel/test-http2-compat-serverresponse-write.js52
2 files changed, 52 insertions, 95 deletions
diff --git a/test/parallel/test-http2-compat-serverresponse-write-no-cb.js b/test/parallel/test-http2-compat-serverresponse-write-no-cb.js
deleted file mode 100644
index a62bb1b0ac..0000000000
--- a/test/parallel/test-http2-compat-serverresponse-write-no-cb.js
+++ /dev/null
@@ -1,95 +0,0 @@
-'use strict';
-
-const { mustCall,
- mustNotCall,
- expectsError,
- hasCrypto, skip } = require('../common');
-if (!hasCrypto)
- skip('missing crypto');
-const { createServer, connect } = require('http2');
-
-// Http2ServerResponse.write does not imply there is a callback
-
-{
- const server = createServer();
- server.listen(0, mustCall(() => {
- const port = server.address().port;
- const url = `http://localhost:${port}`;
- const client = connect(url, mustCall(() => {
- const request = client.request();
- request.resume();
- request.on('end', mustCall());
- request.on('close', mustCall(() => {
- client.close();
- }));
- }));
-
- server.once('request', mustCall((request, response) => {
- client.destroy();
- response.stream.session.on('close', mustCall(() => {
- response.on('error', mustNotCall());
- expectsError(
- () => { response.write('muahaha'); },
- {
- code: 'ERR_HTTP2_INVALID_STREAM'
- }
- );
- server.close();
- }));
- }));
- }));
-}
-
-{
- const server = createServer();
- server.listen(0, mustCall(() => {
- const port = server.address().port;
- const url = `http://localhost:${port}`;
- const client = connect(url, mustCall(() => {
- const request = client.request();
- request.resume();
- request.on('end', mustCall());
- request.on('close', mustCall(() => client.close()));
- }));
-
- server.once('request', mustCall((request, response) => {
- client.destroy();
- response.stream.session.on('close', mustCall(() => {
- expectsError(
- () => response.write('muahaha'),
- {
- code: 'ERR_HTTP2_INVALID_STREAM'
- }
- );
- server.close();
- }));
- }));
- }));
-}
-
-{
- const server = createServer();
- server.listen(0, mustCall(() => {
- const port = server.address().port;
- const url = `http://localhost:${port}`;
- const client = connect(url, mustCall(() => {
- const request = client.request();
- request.resume();
- request.on('end', mustCall());
- request.on('close', mustCall(() => client.close()));
- }));
-
- server.once('request', mustCall((request, response) => {
- response.stream.session.on('close', mustCall(() => {
- expectsError(
- () => response.write('muahaha', 'utf8'),
- {
- code: 'ERR_HTTP2_INVALID_STREAM'
- }
- );
- server.close();
- }));
- client.destroy();
- }));
- }));
-}
diff --git a/test/parallel/test-http2-compat-serverresponse-write.js b/test/parallel/test-http2-compat-serverresponse-write.js
new file mode 100644
index 0000000000..af3029835e
--- /dev/null
+++ b/test/parallel/test-http2-compat-serverresponse-write.js
@@ -0,0 +1,52 @@
+'use strict';
+
+const {
+ mustCall,
+ mustNotCall,
+ expectsError,
+ hasCrypto,
+ skip
+} = require('../common');
+if (!hasCrypto)
+ skip('missing crypto');
+const { createServer, connect } = require('http2');
+const assert = require('assert');
+
+const server = createServer();
+server.listen(0, mustCall(() => {
+ const port = server.address().port;
+ const url = `http://localhost:${port}`;
+ const client = connect(url, mustCall(() => {
+ const request = client.request();
+ request.resume();
+ request.on('end', mustCall());
+ request.on('close', mustCall(() => {
+ client.close();
+ }));
+ }));
+
+ server.once('request', mustCall((request, response) => {
+ // response.write() returns true
+ assert(response.write('muahaha', 'utf8', mustCall()));
+
+ response.stream.close(0, mustCall(() => {
+ response.on('error', mustNotCall());
+
+ // response.write() without cb returns error
+ expectsError(
+ () => { response.write('muahaha'); },
+ {
+ type: Error,
+ code: 'ERR_HTTP2_INVALID_STREAM',
+ message: 'The stream has been destroyed'
+ }
+ );
+
+ // response.write() with cb returns falsy value
+ assert(!response.write('muahaha', mustCall()));
+
+ client.destroy();
+ server.close();
+ }));
+ }));
+}));