Skip to content

Commit

Permalink
fix: extend logging of close timeout errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed May 30, 2023
1 parent 56b9927 commit 1578bde
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,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 @@ -724,6 +725,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 1578bde

Please sign in to comment.