diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2017-09-21 09:09:21 -0400 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-09-25 13:25:35 -0700 |
commit | c705f1067c4ed032184734a5d6185a4f5aa25abf (patch) | |
tree | 5684ed098f5b9e1bbcf77c888cbe847998e09592 /test/parallel/test-http2-compat-serverresponse-drain.js | |
parent | ebc58d7a220011c6f067f12918adb583f2192859 (diff) | |
download | android-node-v8-c705f1067c4ed032184734a5d6185a4f5aa25abf.tar.gz android-node-v8-c705f1067c4ed032184734a5d6185a4f5aa25abf.tar.bz2 android-node-v8-c705f1067c4ed032184734a5d6185a4f5aa25abf.zip |
http2: fix compat stream read handling, add tests
Handle edge case where stream pause is called between resume being
called and actually evaluated. Other minor adjustments to avoid
various edge cases around stream events. Add new tests that cover
all changes.
Fixes: https://github.com/nodejs/node/issues/15491
PR-URL: https://github.com/nodejs/node/pull/15503
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-http2-compat-serverresponse-drain.js')
-rw-r--r-- | test/parallel/test-http2-compat-serverresponse-drain.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/parallel/test-http2-compat-serverresponse-drain.js b/test/parallel/test-http2-compat-serverresponse-drain.js new file mode 100644 index 0000000000..312b7c75ab --- /dev/null +++ b/test/parallel/test-http2-compat-serverresponse-drain.js @@ -0,0 +1,44 @@ +// Flags: --expose-http2 +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); +const assert = require('assert'); +const h2 = require('http2'); + +// Check that drain event is passed from Http2Stream + +const testString = 'tests'; + +const server = h2.createServer(); + +server.on('request', common.mustCall((req, res) => { + res.stream._writableState.highWaterMark = testString.length; + assert.strictEqual(res.write(testString), false); + res.on('drain', common.mustCall(() => res.end(testString))); +})); + +server.listen(0, common.mustCall(() => { + const port = server.address().port; + + const client = h2.connect(`http://localhost:${port}`); + const request = client.request({ + ':path': '/foobar', + ':method': 'POST', + ':scheme': 'http', + ':authority': `localhost:${port}` + }); + request.resume(); + request.end(); + + let data = ''; + request.setEncoding('utf8'); + request.on('data', (chunk) => (data += chunk)); + + request.on('end', common.mustCall(function() { + assert.strictEqual(data, testString.repeat(2)); + client.destroy(); + server.close(); + })); +})); |