Skip to content

Commit

Permalink
fix: extend logging of process timeout errors (#3452)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed May 30, 2023
1 parent f75ab65 commit 4264390
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/vitest/src/node/core.ts
Expand Up @@ -703,14 +703,15 @@ export class Vitest {

async close() {
if (!this.closingPromise) {
const closePromises = this.projects.map(w => w.close())
const closePromises = this.projects.map(w => w.close().then(() => w.server = undefined as any))
// close the core workspace server only once
if (this.coreWorkspace && !this.projects.includes(this.coreWorkspace))
closePromises.push(this.server.close())
this.closingPromise = Promise.allSettled([
this.pool?.close(),
...closePromises,
].filter(Boolean)).then((results) => {
closePromises.push(this.server.close().then(() => this.server = undefined as any))

if (this.pool)
closePromises.push(this.pool.close().then(() => this.pool = undefined))

this.closingPromise = Promise.allSettled(closePromises).then((results) => {
results.filter(r => r.status === 'rejected').forEach((err) => {
this.logger.error('error during close', (err as PromiseRejectedResult).reason)
})
Expand All @@ -727,6 +728,20 @@ export class Vitest {
this.report('onProcessTimeout').then(() => {
console.warn(`close timed out after ${this.config.teardownTimeout}ms`)
this.state.getProcessTimeoutCauses().forEach(cause => console.warn(cause))

if (!this.pool) {
const runningServers = [this.server, ...this.projects.map(p => p.server)].filter(Boolean).length

if (runningServers === 1)
console.warn('Tests closed successfully but something prevents Vite server from exiting')
else if (runningServers > 1)
console.warn(`Tests closed successfully but something prevents ${runningServers} Vite servers from exiting`)
else
console.warn('Tests closed successfully but something prevents the main process from exiting')

console.warn('You can try to identify the cause by enabling "hanging-process" reporter. See https://vitest.dev/config/#reporters')
}

process.exit()
})
}, this.config.teardownTimeout).unref()
Expand Down

0 comments on commit 4264390

Please sign in to comment.