Skip to content

Commit 9755893

Browse files
committed
Address comments
1 parent cfb59c9 commit 9755893

2 files changed

Lines changed: 56 additions & 8 deletions

File tree

test/electron/run_test.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,32 @@ console.log('Launching Electron to run test_usability.js...');
2828
const child = spawn(command, args, {
2929
stdio: 'inherit',
3030
env: { ...process.env, ELECTRON_ENABLE_LOGGING: true },
31+
detached: true,
3132
});
3233

33-
// Kill the child process if it doesn't exit within 30 seconds
34+
// Kill the child process tree if it doesn't exit within 30 seconds
3435
const killTimeout = setTimeout(() => {
3536
console.error('Electron process did not exit in time, killing...');
36-
child.kill('SIGKILL');
37+
try {
38+
process.kill(-child.pid, 'SIGKILL');
39+
} catch (err) {
40+
try {
41+
child.kill('SIGKILL');
42+
} catch (e) {
43+
// Process already dead
44+
}
45+
}
3746
}, 30 * 1000);
3847

39-
child.on('close', (code) => {
48+
child.on('close', (code, signal) => {
4049
clearTimeout(killTimeout);
41-
console.log(`Electron process exited with code ${code}`);
50+
if (code !== null) {
51+
console.log(`Electron process exited with code ${code}`);
52+
} else {
53+
console.log(
54+
`Electron process was terminated by signal ${signal || 'unknown'}`
55+
);
56+
}
4257
if (code === 0) {
4358
console.log('Test Passed!');
4459
process.exit(0);

test/test-message-generation-bin.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ function getNodeVersionInfo() {
3333
.map((x) => parseInt(x));
3434
}
3535

36+
function runCommand(command, args, options) {
37+
const result = childProcess.spawnSync(command, args, options);
38+
if (
39+
result.error ||
40+
(typeof result.status === 'number' && result.status !== 0)
41+
) {
42+
const parts = [
43+
`Failed to run: ${command} ${Array.isArray(args) ? args.join(' ') : ''}`,
44+
];
45+
if (
46+
result.error &&
47+
result.error.code === 'ETIMEDOUT' &&
48+
options &&
49+
options.timeout
50+
) {
51+
parts.push(`Command timed out after ${options.timeout} ms`);
52+
} else if (result.error) {
53+
parts.push(`Error: ${result.error.message}`);
54+
}
55+
if (typeof result.status === 'number' && result.status !== 0) {
56+
parts.push(`Exit status: ${result.status}`);
57+
}
58+
if (result.stdout) {
59+
parts.push(`stdout:\n${result.stdout.toString()}`);
60+
}
61+
if (result.stderr) {
62+
parts.push(`stderr:\n${result.stderr.toString()}`);
63+
}
64+
throw new Error(parts.join('\n'));
65+
}
66+
return result;
67+
}
68+
3669
describe('rclnodejs generate-messages binary-script tests', function () {
3770
let cwd;
3871
let tmpPkg;
@@ -62,7 +95,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
6295
cwd: this.tmpPkg,
6396
timeout: 60 * 1000,
6497
});
65-
childProcess.spawnSync('npm', ['pack', this.cwd], {
98+
runCommand('npm', ['pack', this.cwd], {
6699
// stdio: 'inherit',
67100
shell: true,
68101
cwd: this.tmpPkg,
@@ -82,7 +115,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
82115
return;
83116
}
84117
let tgzPath = path.join(this.tmpPkg, tgz);
85-
childProcess.spawnSync('npm', ['install', tgzPath], {
118+
runCommand('npm', ['install', tgzPath], {
86119
// stdio: 'inherit',
87120
shell: true,
88121
cwd: this.tmpPkg,
@@ -117,7 +150,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
117150

118151
it('test generate-ros-messages script operation', function (done) {
119152
let script = createScriptFolderPath(this.tmpPkg);
120-
childProcess.spawnSync(script, args, {
153+
runCommand(script, args, {
121154
// stdio: 'inherit',
122155
shell: true,
123156
timeout: 120 * 1000,
@@ -136,7 +169,7 @@ describe('rclnodejs generate-messages binary-script tests', function () {
136169
});
137170

138171
it('test npx generate-ros-messages script operation', function (done) {
139-
childProcess.spawnSync('npx', [SCRIPT_NAME, ...args], {
172+
runCommand('npx', [SCRIPT_NAME, ...args], {
140173
// stdio: 'inherit',
141174
shell: true,
142175
cwd: this.tmpPkg,

0 commit comments

Comments
 (0)