Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
don't use PerformanceObserver API
  • Loading branch information
rexagod committed May 2, 2020
commit e691fd33a21752997befae24cef38165713130cc
21 changes: 6 additions & 15 deletions test/parallel/test-http2-byteswritten-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,24 @@ if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const { PerformanceObserver } = require('perf_hooks');

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.end(Buffer.from('9'.repeat(1024)), () => {
http2Server.close();
});
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('response', common.mustCall());
req.on('data', common.mustCall());
req.on('end', common.mustCall(function() {
http2client.close();
observer.disconnect();
http2Server.close();
}));
req.end();
}));

const observer = new PerformanceObserver(common.mustCall(function(items) {
const entry = items.getEntries()[0];
if (entry.name === 'Http2Stream') {
assert.strictEqual(entry.bytesWritten, 1024);
}
}));

observer.observe({ entryTypes: ['http2'] });