Fix randomly failing CI tests (#231)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by Sindre Sorhus · parent 2438df2 · Browse files · 3 files·+13 added−52 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+13 added−52 removed
- other:+13 added−52 removed
Provenance
- Commit
4fb924c- Tree
afaba9b- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
2438df2
3 files changed+13 added−52 removed
modified:fixtures/delay+1 added-6 removed
1 #!/usr/bin/env node2 'use strict';3 4-setTimeout(() => {5- console.log('delay completed');6- process.exit(Number(process.argv[3] || 0));7-}, Number(process.argv[2]));8-9-console.log('delay started');4+setTimeout(() => {}, Number(process.argv[2]));deleted:fixtures/sleeper-4 removed
1-#!/bin/bash2-3-sleep 54-echo "ok"modified:test.js+12 added-42 removed
320 unmodified lines321 322 test('error.killed is true if process was killed directly', async t => {323 const cp = execa('forever');324 325- setTimeout(() => {326- cp.kill();325+ cp.kill();327- }, 100);326 327 const error = await t.throwsAsync(cp, {message: /was killed with SIGTERM/});328 t.true(error.killed);329 });1 unmodified line331 // TODO: Should this really be the case, or should we improve on child_process?332 test('error.killed is false if process was killed indirectly', async t => {333 const cp = execa('forever');334 337- setTimeout(() => {338- process.kill(cp.pid, 'SIGINT');335+ process.kill(cp.pid, 'SIGINT');339- }, 100);336 337 // `process.kill()` is emulated by Node.js on Windows338 const message = process.platform === 'win32' ? /failed with exit code 1/ : /was killed with SIGINT/;339 const error = await t.throwsAsync(cp, {message});7 unmodified lines347 t.false(error.killed);348 t.end();349 });350 355- setTimeout(() => {356- process.kill(cp.pid, 'SIGINT');351+ process.kill(cp.pid, 'SIGINT');357- }, 100);352 });353 }354 355 if (process.platform !== 'win32') {356 test('error.signal is SIGINT', async t => {357 const cp = execa('forever');358 365- setTimeout(() => {366- process.kill(cp.pid, 'SIGINT');359+ process.kill(cp.pid, 'SIGINT');367- }, 100);360 361 const error = await t.throwsAsync(cp, {message: /was killed with SIGINT/});362 t.is(error.signal, 'SIGINT');363 });364 365 test('error.signal is SIGTERM', async t => {366 const cp = execa('forever');367 376- setTimeout(() => {377- process.kill(cp.pid, 'SIGTERM');368+ process.kill(cp.pid, 'SIGTERM');378- }, 100);369 370 const error = await t.throwsAsync(cp, {message: /was killed with SIGTERM/});371 t.is(error.signal, 'SIGTERM');372 });373 374 test('custom error.signal', async t => {385- const error = await t.throwsAsync(execa('delay', ['3000', '0'], {killSignal: 'SIGHUP', timeout: 1500, message: TIMEOUT_REGEXP}));375+ const error = await t.throwsAsync(execa('forever', {killSignal: 'SIGHUP', timeout: 1, message: TIMEOUT_REGEXP}));376 t.is(error.signal, 'SIGHUP');377 });378 }379 14 unmodified lines394 test('error.code is 2', code, 2);395 test('error.code is 3', code, 3);396 test('error.code is 4', code, 4);397 408-test.serial('timeout will kill the process early', async t => {409- const time = Date.now();410- const error = await t.throwsAsync(execa('delay', ['60000', '0'], {timeout: 500, message: TIMEOUT_REGEXP}));411- const diff = Date.now() - time;412-398+test('timeout kills the process if it times out', async t => {399+ const error = await t.throwsAsync(execa('forever', {timeout: 1, message: TIMEOUT_REGEXP}));400 t.true(error.timedOut);414- t.not(error.exitCode, 22);415- t.true(diff < 4000);401 });402 418-test.serial('timeout will kill the process early (sleep)', async t => {419- const time = Date.now();420- const error = await t.throwsAsync(execa('sleeper', [], {timeout: 500, message: TIMEOUT_REGEXP}));421- const diff = Date.now() - time;422-423- t.true(error.timedOut);424- t.not(error.stdout, 'ok');425- t.true(diff < 4000);426-});427-428-test('timeout will not kill the process early', async t => {429- const error = await t.throwsAsync(execa('delay', ['2000', '22'], {timeout: 30000}), {code: 22, message: getExitRegExp('22')});403+test('timeout does not kill the process if it does not time out', async t => {404+ const error = await execa('delay', ['500'], {timeout: 1e8});405 t.false(error.timedOut);406 });407 433-test('timedOut will be false if no timeout was set and zero exit code', async t => {434- const result = await execa('delay', ['1000', '0']);408+test('timedOut is false if no timeout was set', async t => {409+ const result = await execa('noop');410 t.false(result.timedOut);411 });412 438-test('timedOut will be false if no timeout was set and non-zero exit code', async t => {439- const error = await t.throwsAsync(execa('delay', ['1000', '3']), {message: getExitRegExp('3')});440- t.false(error.timedOut);441-});442-413 async function errorMessage(t, expected, ...args) {414 await t.throwsAsync(execa('exit', args), {message: expected});415 }416 246 unmodified lines