summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-short-stream-client-server.js
diff options
context:
space:
mode:
authorMatteo Collina <hello@matteocollina.com>2018-02-20 00:42:48 +0100
committerMatteo Collina <hello@matteocollina.com>2018-02-26 18:25:58 +0100
commitdbe645f11460a8985f5f6e07f9ed829bee43e101 (patch)
tree37cc08ee13bca538107f29b093abd9499b331554 /test/parallel/test-http2-short-stream-client-server.js
parentfcebb16478b6bb1c997958806f65df7f0e2230ac (diff)
downloadandroid-node-v8-dbe645f11460a8985f5f6e07f9ed829bee43e101.tar.gz
android-node-v8-dbe645f11460a8985f5f6e07f9ed829bee43e101.tar.bz2
android-node-v8-dbe645f11460a8985f5f6e07f9ed829bee43e101.zip
http2: fix condition where data is lost
PR-URL: https://github.com/nodejs/node/pull/18895 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-http2-short-stream-client-server.js')
-rw-r--r--test/parallel/test-http2-short-stream-client-server.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/parallel/test-http2-short-stream-client-server.js b/test/parallel/test-http2-short-stream-client-server.js
new file mode 100644
index 0000000000..e632b8d96b
--- /dev/null
+++ b/test/parallel/test-http2-short-stream-client-server.js
@@ -0,0 +1,55 @@
+'use strict';
+
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+const assert = require('assert');
+const http2 = require('http2');
+const { Readable } = require('stream');
+
+const server = http2.createServer();
+server.on('stream', common.mustCall((stream) => {
+ stream.respond({
+ ':status': 200,
+ 'content-type': 'text/html'
+ });
+ const input = new Readable({
+ read() {
+ this.push('test');
+ this.push(null);
+ }
+ });
+ input.pipe(stream);
+}));
+
+
+server.listen(0, common.mustCall(() => {
+ const port = server.address().port;
+ const client = http2.connect(`http://localhost:${port}`);
+
+ const req = client.request();
+
+ req.on('response', common.mustCall((headers) => {
+ assert.strictEqual(headers[':status'], 200);
+ assert.strictEqual(headers['content-type'], 'text/html');
+ }));
+
+ let data = '';
+
+ const notCallClose = common.mustNotCall();
+
+ setTimeout(() => {
+ req.setEncoding('utf8');
+ req.removeListener('close', notCallClose);
+ req.on('close', common.mustCall(() => {
+ server.close();
+ client.close();
+ }));
+ req.on('data', common.mustCallAtLeast((d) => data += d));
+ req.on('end', common.mustCall(() => {
+ assert.strictEqual(data, 'test');
+ }));
+ }, common.platformTimeout(100));
+
+ req.on('close', notCallClose);
+}));