tests; fixes for ts process management
This commit is contained in:
parent
da8401ce16
commit
1b794147ec
@ -15,7 +15,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "vitest run --teardown-timeout=20000 --test-timeout=20000"
|
||||
"test": "vitest run --teardown-timeout=20000 --test-timeout=20000 --sequence.concurrent"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^22.10.5"
|
||||
|
||||
@ -6,3 +6,9 @@ test('test connection timeout', async ({expect}) => {
|
||||
await parentIpc.start();
|
||||
await expect(parentIpc.wait()).rejects.toThrowError('timed out');
|
||||
});
|
||||
|
||||
test('test process stop before connection accept', async ({expect}) => {
|
||||
const parentIpc = new ParentIPC('testdata/sleep3.sh', []);
|
||||
await parentIpc.start();
|
||||
await expect(parentIpc.wait()).rejects.toThrowError('command exited before connection established');
|
||||
});
|
||||
|
||||
@ -45,6 +45,7 @@ abstract class IPCCommon {
|
||||
protected pendingCalls: Record<number, (result: CallResult) => void> = {};
|
||||
protected stopRequested: boolean = false;
|
||||
protected processingCalls: number = 0;
|
||||
protected ready = false;
|
||||
|
||||
protected errorQueue = new AsyncQueue<Error>();
|
||||
protected onClose?: () => void;
|
||||
@ -84,6 +85,8 @@ abstract class IPCCommon {
|
||||
this.raiseErr(new Error(`${ e }`));
|
||||
}
|
||||
});
|
||||
|
||||
this.ready = true;
|
||||
}
|
||||
|
||||
protected processMsg(msg: Message): void {
|
||||
@ -266,11 +269,16 @@ export class ParentIPC extends IPCCommon {
|
||||
|
||||
async wait(): Promise<void> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!this.cmd) throw new Error('Command is not started yet');
|
||||
if (!this.cmd) {
|
||||
reject('Command is not started yet');
|
||||
return;
|
||||
}
|
||||
this.cmd.addListener('close', (code, signal) => {
|
||||
if (signal || code) {
|
||||
if (signal) reject(new Error(`Process exited with signal ${ signal }`));
|
||||
else reject(new Error(`Process exited with code ${ code }`));
|
||||
} else if(!this.ready) {
|
||||
reject('command exited before connection established');
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
|
||||
2
lib/ts/testdata/sleep15.sh
vendored
2
lib/ts/testdata/sleep15.sh
vendored
@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo sleeping...
|
||||
sleep 15s
|
||||
echo slept
|
||||
|
||||
3
lib/ts/testdata/sleep3.sh
vendored
Executable file
3
lib/ts/testdata/sleep3.sh
vendored
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
sleep 3s
|
||||
Loading…
x
Reference in New Issue
Block a user