Skip to content
Myr

Fix randomly failing test (#725)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 0ff8b34 · Browse files · 5 files+22 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+22 added−29 removed

  • tests:+22 added−29 removed

5 files+22 added−29 removed

modified:test/fixtures/nested.js+1 added-2 removed
deleted:test/fixtures/sub-process-exit.js-13 removed
modified:test/fixtures/sub-process.js+1 added
modified:test/kill.js+17 added-11 removed
171 unmodified lines
172});173174// When child process exits before parent process175const spawnAndExit = async (t, cleanup, detached) => {176 await t.notThrowsAsync(execa('sub-process-exit.js', [cleanup, detached]));176 await t.notThrowsAsync(execa('nested.js', [JSON.stringify({cleanup, detached}), 'noop.js']));177};178179test('spawnAndExit', spawnAndExit, false, false);180test('spawnAndExit cleanup', spawnAndExit, true, false);
10 unmodified lines
191192 process.kill(subprocess.pid, signal);193194 await t.throwsAsync(subprocess);195196 // The `cleanup` option can introduce a race condition in this test.197 // This is especially true when run concurrently, so we use `test.serial()` and a manual timeout.198 if (signal === 'SIGTERM' && cleanup && !detached) {199 await setTimeout(1e3);200 }201195 t.false(isRunning(subprocess.pid));203 t.not(isRunning(pid), isKilled);196205 if (!isKilled) {197 if (isKilled) {198 await Promise.race([199 setTimeout(1e4, undefined, {ref: false}),200 pollForProcessExit(pid),201 ]);202 t.is(isRunning(pid), false);203 } else {204 t.is(isRunning(pid), true);205 process.kill(pid, 'SIGKILL');206 }207};208209const pollForProcessExit = async pid => {210 while (isRunning(pid)) {211 // eslint-disable-next-line no-await-in-loop212 await setTimeout(100);213 }214};215216// Without `options.cleanup`:217// - on Windows subprocesses are killed if `options.detached: false`, but not218// if `options.detached: true`219// - on Linux subprocesses are never killed regardless of `options.detached`
1 unmodified line
221// - `options.cleanup` with SIGKILL is a noop, since it cannot be handled222const exitIfWindows = process.platform === 'win32';223test('spawnAndKill SIGTERM', spawnAndKill, ['SIGTERM', false, false, exitIfWindows]);224test('spawnAndKill SIGKILL', spawnAndKill, ['SIGKILL', false, false, exitIfWindows]);219test.serial('spawnAndKill cleanup SIGTERM', spawnAndKill, ['SIGTERM', true, false, true]);225test('spawnAndKill cleanup SIGTERM', spawnAndKill, ['SIGTERM', true, false, true]);226test('spawnAndKill cleanup SIGKILL', spawnAndKill, ['SIGKILL', true, false, exitIfWindows]);227test('spawnAndKill detached SIGTERM', spawnAndKill, ['SIGTERM', false, true, false]);228test('spawnAndKill detached SIGKILL', spawnAndKill, ['SIGKILL', false, true, false]);229test('spawnAndKill cleanup detached SIGTERM', spawnAndKill, ['SIGTERM', true, true, false]);
84 unmodified lines
modified:test/verbose.js+3 added-3 removed