Skip to content

Commit

Permalink
test: add test for Http2ServerResponse#[writableCorked,cork,uncork]
Browse files Browse the repository at this point in the history
PR-URL: #33956
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
rexagod authored and codebytere committed Jun 27, 2020

Verified

This commit was signed with the committer’s verified signature.
codebytere Shelley Vohr
1 parent d61de30 commit d4a2ae0
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/parallel/test-http2-res-corked.js
Original file line number Diff line number Diff line change
@@ -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();
}));
}));
}

0 comments on commit d4a2ae0

Please sign in to comment.