Skip to content

Commit 4c5f45a

Browse files
jisedlacthurka
authored andcommitted
Killing processes during cleanup made more robust
1 parent 9ad783a commit 4c5f45a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

integrations/vscode/src/test/suite/visualvm.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ suite('VisualVm Suite Tests', function () {
6161
});
6262

6363
let testPid: number = 0; // pid of a test Java process
64-
let childProcess: cp.ChildProcessWithoutNullStreams; // test Java process launcher
6564
let visualvmPid: number = 0; // pid of a VisualVM process
6665
test('Manually Selecting Project Process', async function () {
6766

@@ -74,7 +73,7 @@ suite('VisualVm Suite Tests', function () {
7473
try {
7574
const jarFilePath = path.join(projectPath, 'oci/target/oci-1.0-SNAPSHOT.jar');
7675
if (fs.existsSync(jarFilePath)) {
77-
childProcess = cp.spawn('java', [TEST_JAVA_PROCESS_PARAMETER, '-jar', 'oci/target/oci-1.0-SNAPSHOT.jar'], { cwd: projectPath });
76+
cp.spawn('java', [TEST_JAVA_PROCESS_PARAMETER, '-jar', 'oci/target/oci-1.0-SNAPSHOT.jar'], { cwd: projectPath });
7877
} else {
7978
assert(undefined, 'JAR File does not exist ... The build does not done correctly');
8079
}
@@ -287,15 +286,19 @@ suite('VisualVm Suite Tests', function () {
287286

288287
this.afterAll(async () => {
289288
this.timeout(15000);
290-
if (childProcess) {
291-
// TODO: does this throw an error if the process has already finished?
292-
childProcess.kill();
293-
}
294289
if (testPid) {
295-
process.kill(testPid);
290+
try {
291+
process.kill(testPid);
292+
} catch (err) {
293+
console.log(`Failed to kill test process PID=${testPid}: ${err}`)
294+
}
296295
}
297296
if (visualvmPid) {
298-
process.kill(visualvmPid);
297+
try {
298+
process.kill(visualvmPid);
299+
} catch (err) {
300+
console.log(`Failed to kill visualvm process PID=${visualvmPid}: ${err}`)
301+
}
299302
}
300303
// Wait for a while to have all resources released before the final cleanup
301304
await new Promise(f => setTimeout(f, 3000));

0 commit comments

Comments
 (0)