Skip to content

Commit d95f88c

Browse files
committed
Handle termination gracefully
Signed-off-by: Daniel González Lopes <[email protected]>
1 parent 7279543 commit d95f88c

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

.github/workflows/test.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ on:
55
jobs:
66
protocol:
77
runs-on: ubuntu-latest
8-
# env:
9-
# K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
10-
# K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
8+
env:
9+
K6_CLOUD_TOKEN: ${{ secrets.K6_CLOUD_TOKEN }}
10+
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
1111
steps:
1212
- uses: actions/checkout@v4
1313
- name: Setup Grafana k6

dist/index.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -29899,7 +29899,7 @@ const core = __importStar(__nccwpck_require__(2186));
2989929899
const glob = __importStar(__nccwpck_require__(8090));
2990029900
const fs = __importStar(__nccwpck_require__(5630));
2990129901
const child_process_1 = __nccwpck_require__(2081);
29902-
var PIDs = [];
29902+
var TEST_PIDS = [];
2990329903
run();
2990429904
/**
2990529905
* The main function for the action.
@@ -29924,9 +29924,13 @@ async function run() {
2992429924
commands.forEach(command => {
2992529925
const child = runCommand(command);
2992629926
childProcesses.push(child);
29927-
PIDs.push(child.pid);
29927+
TEST_PIDS.push(child.pid);
2992829928
exitPromises.push(new Promise(resolve => {
2992929929
child.on('exit', (code, signal) => {
29930+
const index = TEST_PIDS.indexOf(child.pid);
29931+
if (index > -1) {
29932+
TEST_PIDS.splice(index, 1);
29933+
}
2993029934
if (code !== 0) {
2993129935
if (failFast) {
2993229936
console.log('🚨 Fail fast enabled. Stopping further tests.');
@@ -29954,9 +29958,13 @@ async function run() {
2995429958
else {
2995529959
for (const command of commands) {
2995629960
const child = runCommand(command);
29957-
PIDs.push(child.pid);
29961+
TEST_PIDS.push(child.pid);
2995829962
await new Promise(resolve => {
2995929963
child.on('exit', (code, signal) => {
29964+
const index = TEST_PIDS.indexOf(child.pid);
29965+
if (index > -1) {
29966+
TEST_PIDS.splice(index, 1);
29967+
}
2996029968
if (code !== 0) {
2996129969
if (failFast) {
2996229970
console.log('🚨 Fail fast enabled. Stopping further tests.');
@@ -30013,7 +30021,7 @@ async function run() {
3001330021
exports.run = run;
3001430022
process.on('SIGINT', () => {
3001530023
console.log('🚨 Caught SIGINT. Stoping all tests');
30016-
PIDs.forEach(pid => {
30024+
TEST_PIDS.forEach(pid => {
3001730025
try {
3001830026
process.kill(pid, 'SIGINT');
3001930027
}

src/index.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as glob from '@actions/glob'
33
import * as fs from 'fs-extra'
44
import { spawn } from 'child_process'
55

6-
var PIDs: number[] = [];
6+
var TEST_PIDS: number[] = [];
77

88
run()
99

@@ -34,9 +34,13 @@ export async function run(): Promise<void> {
3434
commands.forEach(command => {
3535
const child = runCommand(command);
3636
childProcesses.push(child);
37-
PIDs.push(child.pid);
37+
TEST_PIDS.push(child.pid);
3838
exitPromises.push(new Promise(resolve => {
3939
child.on('exit', (code: number, signal: string) => {
40+
const index = TEST_PIDS.indexOf(child.pid);
41+
if (index > -1) {
42+
TEST_PIDS.splice(index, 1);
43+
}
4044
if (code !== 0) {
4145
if (failFast) {
4246
console.log('🚨 Fail fast enabled. Stopping further tests.');
@@ -62,9 +66,13 @@ export async function run(): Promise<void> {
6266
} else {
6367
for (const command of commands) {
6468
const child = runCommand(command);
65-
PIDs.push(child.pid);
69+
TEST_PIDS.push(child.pid);
6670
await new Promise<void>(resolve => {
6771
child.on('exit', (code: number, signal: string) => {
72+
const index = TEST_PIDS.indexOf(child.pid);
73+
if (index > -1) {
74+
TEST_PIDS.splice(index, 1);
75+
}
6876
if (code !== 0) {
6977
if (failFast) {
7078
console.log('🚨 Fail fast enabled. Stopping further tests.');
@@ -121,7 +129,7 @@ export async function run(): Promise<void> {
121129

122130
process.on('SIGINT', () => {
123131
console.log('🚨 Caught SIGINT. Stoping all tests')
124-
PIDs.forEach(pid => {
132+
TEST_PIDS.forEach(pid => {
125133
try {
126134
process.kill(pid, 'SIGINT');
127135
} catch (error) {

0 commit comments

Comments
 (0)