summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-client-write-empty-string.js
diff options
context:
space:
mode:
authorXadillaX <i@2333.moe>2018-02-11 15:57:35 +0800
committerAnna Henningsen <anna@addaleax.net>2018-03-02 11:45:32 +0000
commit16facd7ef48b9d43af02009524983b05901dc26b (patch)
treebb5990eaf65362a645dd330930538518e81544d5 /test/parallel/test-http2-client-write-empty-string.js
parent9bc333cae7d03b7ec584c7c7633b114a4468bccd (diff)
downloadandroid-node-v8-16facd7ef48b9d43af02009524983b05901dc26b.tar.gz
android-node-v8-16facd7ef48b9d43af02009524983b05901dc26b.tar.bz2
android-node-v8-16facd7ef48b9d43af02009524983b05901dc26b.zip
test: check endless loop while writing empty string
Refs: https://github.com/nodejs/node/pull/18673 PR-URL: https://github.com/nodejs/node/pull/18924 Refs: https://github.com/nodejs/node/pull/18673 Refs: https://github.com/nodejs/node/blob/v9.5.0/src/node_http2.cc#L1481-L1484 Refs: https://github.com/nodejs/node/blob/v9.5.0/lib/_http_outgoing.js#L659-L661 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-http2-client-write-empty-string.js')
-rw-r--r--test/parallel/test-http2-client-write-empty-string.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/parallel/test-http2-client-write-empty-string.js b/test/parallel/test-http2-client-write-empty-string.js
new file mode 100644
index 0000000000..c10698d417
--- /dev/null
+++ b/test/parallel/test-http2-client-write-empty-string.js
@@ -0,0 +1,54 @@
+'use strict';
+
+const assert = require('assert');
+const http2 = require('http2');
+
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+
+for (const chunkSequence of [
+ [ '' ],
+ [ '', '' ]
+]) {
+ const server = http2.createServer();
+ server.on('stream', common.mustCall((stream, headers, flags) => {
+ stream.respond({ 'content-type': 'text/html' });
+
+ let data = '';
+ stream.on('data', common.mustNotCall((chunk) => {
+ data += chunk.toString();
+ }));
+ stream.on('end', common.mustCall(() => {
+ stream.end(`"${data}"`);
+ }));
+ }));
+
+ server.listen(0, common.mustCall(() => {
+ const port = server.address().port;
+ const client = http2.connect(`http://localhost:${port}`);
+
+ const req = client.request({
+ ':method': 'POST',
+ ':path': '/'
+ });
+
+ req.on('response', common.mustCall((headers) => {
+ assert.strictEqual(headers[':status'], 200);
+ assert.strictEqual(headers['content-type'], 'text/html');
+ }));
+
+ let data = '';
+ req.setEncoding('utf8');
+ req.on('data', common.mustCallAtLeast((d) => data += d));
+ req.on('end', common.mustCall(() => {
+ assert.strictEqual(data, '""');
+ server.close();
+ client.close();
+ }));
+
+ for (const chunk of chunkSequence)
+ req.write(chunk);
+ req.end();
+ }));
+}