Skip to content

Commit

Permalink
http2: add bytesWritten test for Http2Stream
Browse files Browse the repository at this point in the history
note that this is for the `Http2Server` class. I'll soon be
adding one for `Http2SecureServer` as well.

Refs: #29829

PR-URL: #33162
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
rexagod authored and codebytere committed May 11, 2020
1 parent b634d4b commit 41c5524
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/parallel/test-http2-byteswritten-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');

const http2Server = http2.createServer(common.mustCall(function(req, res) {
res.socket.on('finish', common.mustCall(() => {
assert(req.socket.bytesWritten > 0); // 1094
}));
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write(Buffer.from('1'.repeat(1024)));
res.end();
}));

http2Server.listen(0, common.mustCall(function() {
const URL = `http://localhost:${http2Server.address().port}`;
const http2client = http2.connect(URL, { protocol: 'http:' });
const req = http2client.request({ ':method': 'GET', ':path': '/' });
req.on('data', common.mustCall());
req.on('end', common.mustCall(function() {
http2client.close();
http2Server.close();
}));
req.end();
}));

0 comments on commit 41c5524

Please sign in to comment.