From d4a2ae094e1d0b27d71f2cff3c0f259113ba2314 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Fri, 19 Jun 2020 04:53:22 +0530 Subject: [PATCH] test: add test for Http2ServerResponse#[writableCorked,cork,uncork] PR-URL: https://github.com/nodejs/node/pull/33956 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- test/parallel/test-http2-res-corked.js | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/parallel/test-http2-res-corked.js diff --git a/test/parallel/test-http2-res-corked.js b/test/parallel/test-http2-res-corked.js new file mode 100644 index 00000000000000..5a6c623edf0f82 --- /dev/null +++ b/test/parallel/test-http2-res-corked.js @@ -0,0 +1,54 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) { common.skip('missing crypto'); } + +// Test for Http2ServerResponse#[writableCorked,cork,uncork] + +const { strictEqual } = require('assert'); +const http2 = require('http2'); + +{ + let corksLeft = 0; + const server = http2.createServer(common.mustCall((req, res) => { + strictEqual(res.writableCorked, corksLeft); + res.write(Buffer.from('1'.repeat(1024))); + res.cork(); + corksLeft++; + strictEqual(res.writableCorked, corksLeft); + res.write(Buffer.from('1'.repeat(1024))); + res.cork(); + corksLeft++; + strictEqual(res.writableCorked, corksLeft); + res.write(Buffer.from('1'.repeat(1024))); + res.cork(); + corksLeft++; + strictEqual(res.writableCorked, corksLeft); + res.write(Buffer.from('1'.repeat(1024))); + res.cork(); + corksLeft++; + strictEqual(res.writableCorked, corksLeft); + res.uncork(); + corksLeft--; + strictEqual(res.writableCorked, corksLeft); + res.uncork(); + corksLeft--; + strictEqual(res.writableCorked, corksLeft); + res.uncork(); + corksLeft--; + strictEqual(res.writableCorked, corksLeft); + res.uncork(); + corksLeft--; + strictEqual(res.writableCorked, corksLeft); + res.end(); + })); + server.listen(0, common.mustCall(() => { + const URL = `http://localhost:${server.address().port}`; + const client = http2.connect(URL); + const req = client.request(); + req.on('data', common.mustCall(2)); + req.on('end', common.mustCall(() => { + server.close(); + client.close(); + })); + })); +}