test: replace callback with arrow functions
PR-URL: https://github.com/nodejs/node/pull/24490 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
e9545e6f20
commit
9d34a1e3c0
@ -32,7 +32,7 @@ const http = require('http');
|
|||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
const body = 'hello world\n';
|
const body = 'hello world\n';
|
||||||
const server = http.createServer(function(req, res) {
|
const server = http.createServer((req, res) => {
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Length': body.length,
|
'Content-Length': body.length,
|
||||||
'Content-Type': 'text/plain'
|
'Content-Type': 'text/plain'
|
||||||
@ -45,7 +45,7 @@ let keepAliveReqSec = 0;
|
|||||||
let normalReqSec = 0;
|
let normalReqSec = 0;
|
||||||
|
|
||||||
|
|
||||||
function runAb(opts, callback) {
|
const runAb = (opts, callback) => {
|
||||||
const args = [
|
const args = [
|
||||||
'-c', opts.concurrent || 100,
|
'-c', opts.concurrent || 100,
|
||||||
'-t', opts.threads || 2,
|
'-t', opts.threads || 2,
|
||||||
@ -66,11 +66,9 @@ function runAb(opts, callback) {
|
|||||||
|
|
||||||
let stdout;
|
let stdout;
|
||||||
|
|
||||||
child.stdout.on('data', function(data) {
|
child.stdout.on('data', (data) => stdout += data);
|
||||||
stdout += data;
|
|
||||||
});
|
|
||||||
|
|
||||||
child.on('close', function(code, signal) {
|
child.on('close', (code, signal) => {
|
||||||
if (code) {
|
if (code) {
|
||||||
console.error(code, signal);
|
console.error(code, signal);
|
||||||
process.exit(code);
|
process.exit(code);
|
||||||
@ -90,20 +88,20 @@ function runAb(opts, callback) {
|
|||||||
|
|
||||||
callback(reqSec, keepAliveRequests);
|
callback(reqSec, keepAliveRequests);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
server.listen(common.PORT, () => {
|
server.listen(common.PORT, () => {
|
||||||
runAb({ keepalive: true }, (reqSec) => {
|
runAb({ keepalive: true }, (reqSec) => {
|
||||||
keepAliveReqSec = reqSec;
|
keepAliveReqSec = reqSec;
|
||||||
|
|
||||||
runAb({ keepalive: false }, function(reqSec) {
|
runAb({ keepalive: false }, (reqSec) => {
|
||||||
normalReqSec = reqSec;
|
normalReqSec = reqSec;
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
normalReqSec > 50,
|
normalReqSec > 50,
|
||||||
true,
|
true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user