Skip to content

Commit

Permalink
fix(browser): stop the browser rpc when the pool is closed (#6858)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Nov 13, 2024
1 parent 251893b commit 9a0c93d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/browser/src/node/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,13 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
[...files.map(f => relative(project.config.root, f))].join(', '),
)
const promise = waitForTests(method, contextId, project, files)
promises.push(promise)
orchestrator.createTesters(files)
const tester = orchestrator.createTesters(files).catch((error) => {
if (error instanceof Error && error.message.startsWith('[birpc] rpc is closed')) {
return
}
return Promise.reject(error)
})
promises.push(promise, tester)
}
else {
const contextId = crypto.randomUUID()
Expand Down Expand Up @@ -156,6 +161,11 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
async close() {
await Promise.all([...providers].map(provider => provider.close()))
providers.clear()
ctx.resolvedProjects.forEach((project) => {
project.browser?.state.orchestrators.forEach((orchestrator) => {
orchestrator.$close()
})
})
},
runTests: files => runWorkspaceTests('run', files),
collectTests: files => runWorkspaceTests('collect', files),
Expand Down
3 changes: 2 additions & 1 deletion packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export class Vitest {

private coreWorkspaceProject!: WorkspaceProject

private resolvedProjects: WorkspaceProject[] = []
/** @private */
public resolvedProjects: WorkspaceProject[] = []
public projects: WorkspaceProject[] = []

public distPath = distDir
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/types/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export interface BrowserServerStateContext {
export interface BrowserOrchestrator {
createTesters: (files: string[]) => Promise<void>
onCancel: (reason: CancelReason) => Promise<void>
$close: () => void
}

export interface BrowserServerState {
Expand Down

0 comments on commit 9a0c93d

Please sign in to comment.