Skip to content

Commit

Permalink
feat: process timeout to log names of stuck test files
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Mar 19, 2023
1 parent 3573032 commit f47666b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
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
2 changes: 2 additions & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class Vitest {
filenamePattern?: string
runningPromise?: Promise<void>
closingPromise?: Promise<void>
processTimeoutCauses: string[] = []

isFirstRun = true
restartsCount = 0
Expand Down Expand Up @@ -597,6 +598,7 @@ export class Vitest {
setTimeout(() => {
this.report('onProcessTimeout').then(() => {
console.warn(`close timed out after ${this.config.teardownTimeout}ms`)
this.processTimeoutCauses.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.processTimeoutCauses.push(`Failed to terminate worker while running ${files.join(', ')}.`)
else
throw error
}
finally {
port.close()
workerPort.close()
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.

0 comments on commit f47666b

Please sign in to comment.