Skip to content

Commit

Permalink
Use Tree Kill
Browse files Browse the repository at this point in the history
  • Loading branch information
InversionSpaces committed Oct 18, 2023
1 parent f3523d1 commit fb8bb7e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"@types/jest": "^29.5.5",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"tree-kill": "^1.2.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"scripts": {
"build": "tsc",
"test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --verbose"
}
},
"prettier": {}
}
5 changes: 0 additions & 5 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,5 @@ describe("integration tests", () => {
} finally {
expect(gateway.stop()).toBeTruthy();
}

// @ts-ignore
console.log(process._getActiveHandles());
// @ts-ignore
console.log(process._getActiveRequests());
});
});
18 changes: 15 additions & 3 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import { relative } from "path";
import { execFile, ChildProcess } from "child_process";

import treeKill from "tree-kill";

import { CONFIG_PATH, readConfig } from "./config";

export async function execute(
Expand All @@ -41,10 +43,11 @@ export async function fluence(...args: string[]): Promise<[string, string]> {
export class Gateway {
constructor(
private readonly gateway: ChildProcess,
private readonly port: number
private readonly port: number,
) {}

public stop(): boolean {
public async stop(): Promise<boolean> {
console.log(this.gateway.pid);
if (this.gateway.stdin) {
this.gateway.stdin.end();
}
Expand All @@ -55,7 +58,16 @@ export class Gateway {
this.gateway.stderr.destroy();
}
if (this.gateway.pid) {
process.kill(this.gateway.pid);
const pid = this.gateway.pid;
await new Promise<void>((resolve, reject) =>
treeKill(pid, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
}),
);
}
return this.gateway.kill();
}
Expand Down

0 comments on commit fb8bb7e

Please sign in to comment.