From c1044232e9b82f461ccd2cd09fef8358879a6f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 18 Jan 2021 16:03:28 +0000 Subject: [PATCH] fix: remove unwanted async calls --- test/stress/child.js | 14 +++++++------- test/stress/index.js | 6 +++--- test/stress/scripts/index.js | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/stress/child.js b/test/stress/child.js index 1f07c37f..c6a7d9a1 100644 --- a/test/stress/child.js +++ b/test/stress/child.js @@ -12,19 +12,19 @@ const variables = require('./utils/variables') var certificate = {} var connectionInfo = {} -async function getCert (machineIndex) { +const getCert = machineIndex => { const key = fs.readFile(path.resolve(__dirname, 'machines', `${machineIndex}`, 'client.key')) const cert = fs.readFile(path.resolve(__dirname, 'machines', `${machineIndex}`, 'client.pem')) - return Promise.all([key, cert]).then(values => { - return { key: values[0], cert: values[1] } + return Promise.all([key, cert]).then(([key, cert]) => { + return { key, cert } }).catch(err => { - console.err('The following error when reading the certificate: ', err) + console.error('The following error when reading the certificate: ', err) return null }) } -async function getConnectionInfo (machineIndex) { +const getConnectionInfo = machineIndex => { return fs.readFile(path.resolve(__dirname, 'machines', `${machineIndex}`, 'connection_info.json')) } @@ -32,7 +32,7 @@ let counter = 0 const requestTimes = [] let latestResponseTime = 0 -function request (machineIndex, pid) { +const request = (machineIndex, pid) => { performance.mark('A') https.get({ hostname: 'localhost', @@ -73,7 +73,7 @@ process.on('message', async (msg) => { certificate = values[0] connectionInfo = JSON.parse(values[1]) }).catch(err => { - console.err('The following error occurred during certificate parsing: ', err) + console.error('The following error occurred during certificate parsing: ', err) }) if (msg.hasVariance) await new Promise(resolve => setTimeout(resolve, utils.randomIntFromInterval(1, variables.POLLING_INTERVAL))) diff --git a/test/stress/index.js b/test/stress/index.js index c22b81f9..afe6de90 100644 --- a/test/stress/index.js +++ b/test/stress/index.js @@ -5,8 +5,8 @@ const minimist = require('minimist') const cmd = require('./scripts') const variables = require('./utils/variables') -async function createMachines (numberOfMachines) { - await cmd.execCommand( +function createMachines (numberOfMachines) { + return cmd.execCommand( `bash ./scripts/create-machines.sh ${numberOfMachines} ${variables.SERVER_CERT_PATH} ${variables.MACHINE_PATH}` ) } @@ -20,8 +20,8 @@ async function run (args = minimist(process.argv.slice(2))) { const NUMBER_OF_MACHINES = args._[0] const HAS_VARIANCE = args.v || false - startServer() await createMachines(NUMBER_OF_MACHINES) + startServer() for (let i = 1; i <= NUMBER_OF_MACHINES; i++) { const forked = fork('child.js') diff --git a/test/stress/scripts/index.js b/test/stress/scripts/index.js index a77010af..991b2d19 100644 --- a/test/stress/scripts/index.js +++ b/test/stress/scripts/index.js @@ -5,7 +5,7 @@ const exec = require('child_process').exec * @param {String} cmd * @return {Object} { stdout: String, stderr: String } */ -async function execCommand (cmd) { +function execCommand (cmd) { return new Promise(function (resolve, reject) { const proc = exec(cmd, (err, stdout, stderr) => { if (err) {