@@ -22,13 +22,8 @@ const suppressWarningsPath = resolve(rootDir, './suppress-warnings.cjs')
2222
2323function createChildProcessChannel ( project : TestProject , collect : boolean ) {
2424 const emitter = new EventEmitter ( )
25- const cleanup = ( ) => emitter . removeAllListeners ( )
2625
2726 const events = { message : 'message' , response : 'response' }
28- const channel : TinypoolChannel = {
29- onMessage : callback => emitter . on ( events . message , callback ) ,
30- postMessage : message => emitter . emit ( events . response , message ) ,
31- }
3227
3328 const rpc = createBirpc < RunnerRPC , RuntimeRPC > (
3429 createMethodsRPC ( project , { cacheFs : true , collect } ) ,
@@ -56,15 +51,22 @@ function createChildProcessChannel(project: TestProject, collect: boolean) {
5651 on ( fn ) {
5752 emitter . on ( events . response , fn )
5853 } ,
59- onTimeoutError ( functionName ) {
60- throw new Error ( `[vitest-pool]: Timeout calling "${ functionName } "` )
61- } ,
54+ timeout : - 1 ,
6255 } ,
6356 )
6457
6558 project . vitest . onCancel ( reason => rpc . onCancel ( reason ) )
6659
67- return { channel, cleanup }
60+ const channel = {
61+ onMessage : callback => emitter . on ( events . message , callback ) ,
62+ postMessage : message => emitter . emit ( events . response , message ) ,
63+ onClose : ( ) => {
64+ emitter . removeAllListeners ( )
65+ rpc . $close ( new Error ( '[vitest-pool]: Pending methods while closing rpc' ) )
66+ } ,
67+ } satisfies TinypoolChannel
68+
69+ return { channel }
6870}
6971
7072export function createVmForksPool (
@@ -131,7 +133,7 @@ export function createVmForksPool(
131133 const paths = files . map ( f => f . filepath )
132134 vitest . state . clearFiles ( project , paths )
133135
134- const { channel, cleanup } = createChildProcessChannel ( project , name === 'collect' )
136+ const { channel } = createChildProcessChannel ( project , name === 'collect' )
135137 const workerId = ++ id
136138 const data : ContextRPC = {
137139 pool : 'forks' ,
@@ -170,7 +172,7 @@ export function createVmForksPool(
170172 }
171173 }
172174 finally {
173- cleanup ( )
175+ channel . onClose ( )
174176 }
175177 }
176178
0 commit comments