From 285a5cc9dd77daefadc6bbf3ef3b0727f8bfa41d Mon Sep 17 00:00:00 2001 From: Al Marks Date: Tue, 28 Jan 2025 13:08:08 -0800 Subject: [PATCH] Increase timeout and set flakiness --- src/test/failures.test.ts | 264 ++++++++++++++++++++------------------ 1 file changed, 138 insertions(+), 126 deletions(-) diff --git a/src/test/failures.test.ts b/src/test/failures.test.ts index ca982537c..de29d96cc 100644 --- a/src/test/failures.test.ts +++ b/src/test/failures.test.ts @@ -6,7 +6,7 @@ import {suite} from 'uvu'; import * as assert from 'uvu/assert'; -import {rigTest} from './util/rig-test.js'; +import {DEFAULT_UVU_TIMEOUT, rigTest} from './util/rig-test.js'; import type {ExitResult} from './util/test-rig.js'; const test = suite(); @@ -483,152 +483,164 @@ test( test( 'unexpected input file deletion during fingerprinting', - rigTest(async ({rig}) => { - // Spam our input file with writes and deletes out-of-band with wireit. - let spamming = true; - void (async () => { - while (spamming) { - try { - await rig.write('input', Math.random()); - await rig.delete('input'); - } catch { - // Sometimes we get an EPERM error here on Windows CI. Probably - // writing too fast, just sleep a bit. - await new Promise((resolve) => setTimeout(resolve, 1000)); + rigTest( + async ({rig}) => { + // Spam our input file with writes and deletes out-of-band with wireit. + let spamming = true; + void (async () => { + while (spamming) { + try { + await rig.write('input', Math.random()); + await rig.delete('input'); + } catch { + // Sometimes we get an EPERM error here on Windows CI. Probably + // writing too fast, just sleep a bit. + await new Promise((resolve) => setTimeout(resolve, 1000)); + } } - } - })(); - - let finalExit: ExitResult; - try { - // It could take multiple attempts to hit the race condition. - for (let i = 0; i < 100; i++) { - const failer = await rig.newCommand(); - await rig.write({ - 'package.json': { - scripts: { - main: 'wireit', - failer: 'wireit', - }, - wireit: { - main: { - dependencies: ['failer'], + })(); + + let finalExit: ExitResult; + try { + // It could take multiple attempts to hit the race condition. + for (let i = 0; i < 100; i++) { + const failer = await rig.newCommand(); + await rig.write({ + 'package.json': { + scripts: { + main: 'wireit', + failer: 'wireit', }, - failer: { - command: failer.command, - files: ['input'], - output: ['output'], + wireit: { + main: { + dependencies: ['failer'], + }, + failer: { + command: failer.command, + files: ['input'], + output: ['output'], + }, }, }, - }, - }); - const wireit = rig.exec('npm run main'); - // If the error occurs, it will happen before invocation. - const exitOrInvocation = await Promise.race([ - wireit.exit, - failer.nextInvocation(), - ]); - if ('code' in exitOrInvocation) { - if (exitOrInvocation.stderr.includes('EPERM')) { - // See note about EPERM above, it can also happen within wireit. - await new Promise((resolve) => setTimeout(resolve, 1000)); - continue; - } else { - finalExit = exitOrInvocation; - break; + }); + const wireit = rig.exec('npm run main'); + // If the error occurs, it will happen before invocation. + const exitOrInvocation = await Promise.race([ + wireit.exit, + failer.nextInvocation(), + ]); + if ('code' in exitOrInvocation) { + if (exitOrInvocation.stderr.includes('EPERM')) { + // See note about EPERM above, it can also happen within wireit. + await new Promise((resolve) => setTimeout(resolve, 1000)); + continue; + } else { + finalExit = exitOrInvocation; + break; + } } - } - await rig.write('output', '1'); - exitOrInvocation.exit(0); - finalExit = await wireit.exit; - if (finalExit.code !== 0) { - if (finalExit.stderr.includes('EPERM')) { - // See note about EPERM above, it can also happen within wireit. - await new Promise((resolve) => setTimeout(resolve, 1000)); - } else { - break; + await rig.write('output', '1'); + exitOrInvocation.exit(0); + finalExit = await wireit.exit; + if (finalExit.code !== 0) { + if (finalExit.stderr.includes('EPERM')) { + // See note about EPERM above, it can also happen within wireit. + await new Promise((resolve) => setTimeout(resolve, 1000)); + } else { + break; + } } } + } finally { + spamming = false; } - } finally { - spamming = false; - } - assert.equal(finalExit!.code, 1); - assert.match( - finalExit!.stderr, - `[failer] Input file "${rig.resolve('input')}" was deleted unexpectedly.` + - ` Is another process writing to the same location?`, - ); - }), + assert.equal(finalExit!.code, 1); + assert.match( + finalExit!.stderr, + `[failer] Input file "${rig.resolve('input')}" was deleted unexpectedly.` + + ` Is another process writing to the same location?`, + ); + }, + { + flaky: true, + ms: DEFAULT_UVU_TIMEOUT * 2, + }, + ), ); test( 'unexpected output file deletion during manifest generation', - rigTest(async ({rig}) => { - // Spam our output file with writes and deletes out-of-band with wireit. - let spamming = true; - void (async () => { - while (spamming) { - try { - await rig.write('output', Math.random()); - await rig.delete('output'); - } catch { - // Sometimes we get an EPERM error here on Windows CI. Probably - // writing too fast, just sleep a bit. - await new Promise((resolve) => setTimeout(resolve, 1000)); + rigTest( + async ({rig}) => { + // Spam our output file with writes and deletes out-of-band with wireit. + let spamming = true; + void (async () => { + while (spamming) { + try { + await rig.write('output', Math.random()); + await rig.delete('output'); + } catch { + // Sometimes we get an EPERM error here on Windows CI. Probably + // writing too fast, just sleep a bit. + await new Promise((resolve) => setTimeout(resolve, 1000)); + } } - } - })(); - - let finalExit: ExitResult; - try { - // It could take multiple attempts to hit the race condition. - for (let i = 0; i < 100; i++) { - const failer = await rig.newCommand(); - await rig.write({ - 'package.json': { - scripts: { - main: 'wireit', - failer: 'wireit', - }, - wireit: { - main: { - dependencies: ['failer'], + })(); + + let finalExit: ExitResult; + try { + // It could take multiple attempts to hit the race condition. + for (let i = 0; i < 100; i++) { + const failer = await rig.newCommand(); + await rig.write({ + 'package.json': { + scripts: { + main: 'wireit', + failer: 'wireit', }, - failer: { - command: failer.command, - files: ['input'], - output: ['output'], + wireit: { + main: { + dependencies: ['failer'], + }, + failer: { + command: failer.command, + files: ['input'], + output: ['output'], + }, }, }, - }, - }); - const wireit = rig.exec('npm run main'); - const failerInv = await failer.nextInvocation(); - await rig.write('output', '1'); - failerInv.exit(0); - finalExit = await wireit.exit; - if (finalExit.code !== 0) { - if (finalExit.stderr.includes('EPERM')) { - // See note about EPERM above, it can also happen within wireit. - await new Promise((resolve) => setTimeout(resolve, 1000)); - } else { - break; + }); + const wireit = rig.exec('npm run main'); + const failerInv = await failer.nextInvocation(); + await rig.write('output', '1'); + failerInv.exit(0); + finalExit = await wireit.exit; + if (finalExit.code !== 0) { + if (finalExit.stderr.includes('EPERM')) { + // See note about EPERM above, it can also happen within wireit. + await new Promise((resolve) => setTimeout(resolve, 1000)); + } else { + break; + } } } + } finally { + spamming = false; } - } finally { - spamming = false; - } - assert.equal(finalExit!.code, 1); - assert.match( - finalExit!.stderr, - `[failer] Output file "${rig.resolve('output')}" was deleted unexpectedly.` + - ` Is another process writing to the same location?`, - ); - }), + assert.equal(finalExit!.code, 1); + assert.match( + finalExit!.stderr, + `[failer] Output file "${rig.resolve('output')}" was deleted unexpectedly.` + + ` Is another process writing to the same location?`, + ); + }, + { + flaky: true, + ms: DEFAULT_UVU_TIMEOUT * 2, + }, + ), ); test.run();