test(subprocess): publish exit fixture state atomically
This commit is contained in:
1 parent
bd1083d78a
commit
96442bd4e5
1 file changed
+4
-2
@@ -1,5 +1,5 @@
|
||||
import { spawn } from 'node:child_process'
|
||||
import { writeFile } from 'node:fs/promises'
|
||||
import { rename, writeFile } from 'node:fs/promises'
|
||||
|
||||
const [statePath] = process.argv.slice(2)
|
||||
if (statePath === undefined) throw new Error('usage: managed-tree.ts <state-path>')
|
||||
@@ -12,5 +12,7 @@ const descendant = spawn(process.execPath, [
|
||||
], { stdio: 'ignore' })
|
||||
if (descendant.pid === undefined) throw new Error('managed descendant did not publish a pid')
|
||||
|
||||
await writeFile(statePath, JSON.stringify({ root: process.pid, descendant: descendant.pid }))
|
||||
const pendingStatePath = `${statePath}.pending-${process.pid}`
|
||||
await writeFile(pendingStatePath, JSON.stringify({ root: process.pid, descendant: descendant.pid }))
|
||||
await rename(pendingStatePath, statePath)
|
||||
setInterval(() => {}, 60_000)
|
||||
Reference in new issue
Block a user