Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: process timeout to log names of stuck test files #3031

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"std-env": "^3.3.1",
"strip-literal": "^1.0.0",
"tinybench": "^2.3.1",
"tinypool": "^0.3.1",
"tinypool": "^0.4.0",
"tinyspy": "^1.0.2",
"vite": "^3.0.0 || ^4.0.0",
"vite-node": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ export class Vitest {
setTimeout(() => {
this.report('onProcessTimeout').then(() => {
console.warn(`close timed out after ${this.config.teardownTimeout}ms`)
this.state.getProcessTimeoutCauses().forEach(cause => console.warn(cause))
process.exit()
})
}, this.config.teardownTimeout).unref()
Expand Down
9 changes: 9 additions & 0 deletions packages/vitest/src/node/pools/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export function createThreadsPool(ctx: Vitest, { execArgv, env }: PoolProcessOpt

env,
execArgv,

terminateTimeout: ctx.config.teardownTimeout,
}

if (ctx.config.isolate) {
Expand Down Expand Up @@ -87,6 +89,13 @@ export function createThreadsPool(ctx: Vitest, { execArgv, env }: PoolProcessOpt
try {
await pool.run(data, { transferList: [workerPort], name })
}
catch (error) {
// Worker got stuck and won't terminate - this may cause process to hang
if (error instanceof Error && /Failed to terminate worker/.test(error.message))
ctx.state.addProcessTimeoutCause(`Failed to terminate worker while running ${files.join(', ')}.`)
else
throw error
}
finally {
port.close()
workerPort.close()
Expand Down
9 changes: 9 additions & 0 deletions packages/vitest/src/node/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class StateManager {
idMap = new Map<string, Task>()
taskFileMap = new WeakMap<Task, File>()
errorsSet = new Set<unknown>()
processTimeoutCauses = new Set<string>()

catchError(err: unknown, type: string): void {
if (isAggregateError(err))
Expand All @@ -39,6 +40,14 @@ export class StateManager {
return Array.from(this.errorsSet.values())
}

addProcessTimeoutCause(cause: string) {
this.processTimeoutCauses.add(cause)
}

getProcessTimeoutCauses() {
return Array.from(this.processTimeoutCauses.values())
}

getPaths() {
return Array.from(this.pathsSet)
}
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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