Skip to content

Commit 0f43d2a

Browse files
committed
fix: should catch onTestCaseResult rpc timeout error
1 parent f83c7ef commit 0f43d2a

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

packages/core/src/runtime/worker/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ const preparePool = async ({
6565

6666
const cleanupFns: (() => MaybePromise<void>)[] = [];
6767

68-
const { rpc } = createRuntimeRpc(createForksRpcOptions());
68+
const originalConsole = global.console;
69+
70+
const { rpc } = createRuntimeRpc(createForksRpcOptions(), {
71+
originalConsole,
72+
});
6973
const {
7074
runtimeConfig: {
7175
globals,

packages/core/src/runtime/worker/rpc.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import v8 from 'node:v8';
22
import { type BirpcOptions, type BirpcReturn, createBirpc } from 'birpc';
33
import type { TinypoolWorkerMessage } from 'tinypool';
4-
import type { RuntimeRPC, ServerRPC } from '../../types';
4+
import type { RuntimeRPC, ServerRPC, TestResult } from '../../types';
55

66
export type WorkerRPC = BirpcReturn<RuntimeRPC, ServerRPC>;
77

@@ -43,8 +43,37 @@ export function createRuntimeRpc(
4343
BirpcOptions<void>,
4444
'on' | 'post' | 'serialize' | 'deserialize'
4545
>,
46+
{
47+
originalConsole,
48+
}: {
49+
originalConsole: Console;
50+
},
4651
): { rpc: WorkerRPC } {
47-
const rpc = createBirpc<RuntimeRPC, ServerRPC>({}, options);
52+
const rpc = createBirpc<RuntimeRPC, ServerRPC>(
53+
{},
54+
{
55+
...options,
56+
onTimeoutError: (functionName, error) => {
57+
switch (functionName) {
58+
case 'onTestCaseResult': {
59+
const caseResult = error[0] as unknown as TestResult;
60+
console.error(
61+
`[Rstest] timeout on calling "onTestCaseResult" rpc method (Case: "${caseResult.name}", Result: "${caseResult.status}")`,
62+
);
63+
return true;
64+
}
65+
case 'onConsoleLog': {
66+
originalConsole.error(
67+
`[Rstest] timeout on calling "onConsoleLog" rpc method (Original log: ${error[0].content})`,
68+
);
69+
return true;
70+
}
71+
default:
72+
return false;
73+
}
74+
},
75+
},
76+
);
4877

4978
return {
5079
rpc,

0 commit comments

Comments
 (0)