test(subprocess): accept zombie quiescence
This commit is contained in:
@@ -60,7 +60,7 @@ function spec(command: string, overrides: SpecOverrides = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Poll until a pid no longer exists (kill(pid, 0) throws ESRCH). */
|
/** Poll until a pid no longer exists, or is only a zombie on Linux. */
|
||||||
async function waitGone(pid: number, timeoutMs = 5_000): Promise<void> {
|
async function waitGone(pid: number, timeoutMs = 5_000): Promise<void> {
|
||||||
const deadline = Date.now() + timeoutMs
|
const deadline = Date.now() + timeoutMs
|
||||||
while (Date.now() < deadline) {
|
while (Date.now() < deadline) {
|
||||||
@@ -69,6 +69,16 @@ async function waitGone(pid: number, timeoutMs = 5_000): Promise<void> {
|
|||||||
} catch {
|
} catch {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (process.platform === 'linux') {
|
||||||
|
try {
|
||||||
|
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8')
|
||||||
|
const state = stat.slice(stat.lastIndexOf(')') + 2, stat.lastIndexOf(')') + 3)
|
||||||
|
if (state === 'Z' || state === 'X') return
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, 20))
|
await new Promise(resolve => setTimeout(resolve, 20))
|
||||||
}
|
}
|
||||||
throw new Error(`pid ${pid} still alive after ${timeoutMs}ms`)
|
throw new Error(`pid ${pid} still alive after ${timeoutMs}ms`)
|
||||||
|
|||||||
Reference in New Issue
Block a user