Skip to content

Commit c1dfc7b

Browse files
committed
even better logs...
1 parent 0b5d06d commit c1dfc7b

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

dev-packages/node-overhead-gh-action/lib/getOverheadMeasurements.mjs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ async function getMeasurements(instrumentFile) {
1515

1616
const cmd = `node ${args.join(' ')}`;
1717

18+
log('--------------------------------');
1819
log(`Getting measurements for "${cmd}"`);
1920

20-
const [appProcess, appProcessClosed] = await startAppProcess(cmd);
21+
const killAppProcess = await startAppProcess(cmd);
2122

2223
log('Example app listening, running autocannon...');
2324

@@ -26,8 +27,9 @@ async function getMeasurements(instrumentFile) {
2627
} catch (error) {
2728
log(`Error running autocannon: ${error}`);
2829
} finally {
29-
appProcess.kill('SIGKILL');
30-
await appProcessClosed;
30+
log('Killing app process...');
31+
await killAppProcess();
32+
log('App process killed');
3133
}
3234
}
3335

@@ -38,9 +40,9 @@ async function startAppProcess(cmd) {
3840

3941
// Promise to keep track of the app process being closed
4042
let resolveAppClose, rejectAppClose;
41-
const appClosePromise = new Promise((res, rej) => {
42-
resolveAppClose = res;
43-
rejectAppClose = rej;
43+
const appClosePromise = new Promise((resolve, reject) => {
44+
resolveAppClose = resolve;
45+
rejectAppClose = reject;
4446
});
4547

4648
appProcess.on('close', code => {
@@ -66,7 +68,10 @@ async function startAppProcess(cmd) {
6668
});
6769
});
6870

69-
return [appProcess, appClosePromise];
71+
return async () => {
72+
appProcess.kill('SIGKILL');
73+
await appClosePromise;
74+
};
7075
}
7176

7277
async function startAutocannonProcess() {
@@ -88,15 +93,18 @@ async function startAutocannonProcess() {
8893
return new Promise((resolve, reject) => {
8994
autocannon.stderr.on('data', data => {
9095
log(`autocannon stderr: ${data}`);
91-
autocannon.kill();
92-
reject(data);
96+
autocannon.kill('SIGKILL');
9397
});
9498

9599
autocannon.on('close', code => {
96100
log(`autocannon closed with code ${code}`);
97101
log(`Average requests: ${lastJson?.requests.average}`);
98102

99-
resolve(lastJson?.requests.average);
103+
if (code && code !== 0) {
104+
reject(new Error(`Autocannon process exited with code ${code}`));
105+
} else {
106+
resolve(lastJson?.requests.average);
107+
}
100108
});
101109
});
102110
}

0 commit comments

Comments
 (0)