Skip to content

Commit

Permalink
Use execa
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Jul 2, 2024
1 parent 30f18b2 commit de8b4f8
Show file tree
Hide file tree
Showing 3 changed files with 848 additions and 4,215 deletions.
17 changes: 10 additions & 7 deletions __tests__/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import assert from 'node:assert'
import { dirname, join } from 'node:path'
import { afterEach, beforeEach, describe, test } from 'node:test'
import { fileURLToPath } from 'node:url'
import { spawn, untilTerminated } from '../processes'
import { ChildProcess } from 'node:child_process'
import { ExecaError, execa } from 'execa'

async function sleep(timeout: number) {
return new Promise((resolve) => setTimeout(resolve, timeout))
Expand Down Expand Up @@ -33,25 +32,29 @@ const engines = ['elasticsearch', 'opensearch']
engines.forEach((engine) =>
signals.forEach((signal) => {
describe(`${engine} stops when sent signal ${signal}`, () => {
let process: ChildProcess
let process: ReturnType<typeof execa> | undefined

beforeEach(async () => {
// FIXME: replace with import.meta.resolve once it is stable in Node.js
const cwd = join(dirname(fileURLToPath(import.meta.url)), engine)

process = await spawn('npx', ['arc', 'sandbox'], {
process = execa('arc', ['sandbox'], {
cwd,
preferLocal: true,
forceKillAfterDelay: false,
stdio: 'inherit',
})
})

afterEach(async () => {
if (process) {
const processIsDead = untilTerminated(process)

assert.ok(process.kill(signal))
// Make sure arc sandbox is dead
await processIsDead
try {
await process
} catch (e) {
if (!(e instanceof ExecaError)) throw e
}
// Give subprocesses some time to die
await sleep(1000)

Expand Down
Loading

0 comments on commit de8b4f8

Please sign in to comment.