Skip to content
Myr

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

3 files+13 added−52 removed

modified:fixtures/delay+1 added-6 removed
1#!/usr/bin/env node2'use strict';34setTimeout(() => {5 console.log('delay completed');6 process.exit(Number(process.argv[3] || 0));7}, Number(process.argv[2]));89console.log('delay started');4setTimeout(() => {}, Number(process.argv[2]));
deleted:fixtures/sleeper-4 removed
1#!/bin/bash23sleep 54echo "ok"
modified:test.js+12 added-42 removed
320 unmodified lines
321322test('error.killed is true if process was killed directly', async t => {323 const cp = execa('forever');324325 setTimeout(() => {326 cp.kill();325 cp.kill();327 }, 100);326327 const error = await t.throwsAsync(cp, {message: /was killed with SIGTERM/});328 t.true(error.killed);329});
1 unmodified line
331// TODO: Should this really be the case, or should we improve on child_process?332test('error.killed is false if process was killed indirectly', async t => {333 const cp = execa('forever');334337 setTimeout(() => {338 process.kill(cp.pid, 'SIGINT');335 process.kill(cp.pid, 'SIGINT');339 }, 100);336337 // `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 lines
347 t.false(error.killed);348 t.end();349 });350355 setTimeout(() => {356 process.kill(cp.pid, 'SIGINT');351 process.kill(cp.pid, 'SIGINT');357 }, 100);352 });353}354355if (process.platform !== 'win32') {356 test('error.signal is SIGINT', async t => {357 const cp = execa('forever');358365 setTimeout(() => {366 process.kill(cp.pid, 'SIGINT');359 process.kill(cp.pid, 'SIGINT');367 }, 100);360361 const error = await t.throwsAsync(cp, {message: /was killed with SIGINT/});362 t.is(error.signal, 'SIGINT');363 });364365 test('error.signal is SIGTERM', async t => {366 const cp = execa('forever');367376 setTimeout(() => {377 process.kill(cp.pid, 'SIGTERM');368 process.kill(cp.pid, 'SIGTERM');378 }, 100);369370 const error = await t.throwsAsync(cp, {message: /was killed with SIGTERM/});371 t.is(error.signal, 'SIGTERM');372 });373374 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 lines
394test('error.code is 2', code, 2);395test('error.code is 3', code, 3);396test('error.code is 4', code, 4);397408test.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;412398test('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});402418test.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;422423 t.true(error.timedOut);424 t.not(error.stdout, 'ok');425 t.true(diff < 4000);426});427428test('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')});403test('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});407433test('timedOut will be false if no timeout was set and zero exit code', async t => {434 const result = await execa('delay', ['1000', '0']);408test('timedOut is false if no timeout was set', async t => {409 const result = await execa('noop');410 t.false(result.timedOut);411});412438test('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});442413async function errorMessage(t, expected, ...args) {414 await t.throwsAsync(execa('exit', args), {message: expected});415}416
246 unmodified lines