From 2812759f9352e2d180aeea8c1999dd2c6ab36371 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 24 Oct 2018 19:23:25 -0700 Subject: test: add test-benchmark-http2 PR-URL: https://github.com/nodejs/node/pull/23863 Reviewed-By: Anatoli Papirovski Reviewed-By: James M Snell --- benchmark/_test-double-benchmarker.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'benchmark/_test-double-benchmarker.js') diff --git a/benchmark/_test-double-benchmarker.js b/benchmark/_test-double-benchmarker.js index e2a0eb1312..b9379b907f 100644 --- a/benchmark/_test-double-benchmarker.js +++ b/benchmark/_test-double-benchmarker.js @@ -1,6 +1,11 @@ 'use strict'; -const http = require('http'); +const myModule = process.argv[2]; +if (!['http', 'http2'].includes(myModule)) { + throw new Error(`Invalid module for benchmark test double: ${myModule}`); +} + +const http = require(myModule); const duration = process.env.duration || 0; const url = process.env.test_url; @@ -8,8 +13,8 @@ const url = process.env.test_url; const start = process.hrtime(); let throughput = 0; -function request(res) { - res.on('data', () => {}); +function request(res, client) { + res.resume(); res.on('error', () => {}); res.on('end', () => { throughput++; @@ -18,12 +23,21 @@ function request(res) { run(); } else { console.log(JSON.stringify({ throughput })); + if (client) { + client.destroy(); + } } }); } function run() { - http.get(url, request); + if (http.get) { // HTTP + http.get(url, request); + } else { // HTTP/2 + const client = http.connect(url); + client.on('error', (e) => { throw e; }); + request(client.request(), client); + } } run(); -- cgit v1.2.3