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 26, 2023
1 parent 56b9927 commit cc390f3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/vitest/src/node/core.ts
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.filter(Boolean)).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,18 @@ 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')
}

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

0 comments on commit cc390f3

Please sign in to comment.