Skip to content

Commit

Permalink
Increase timeout and set flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
aomarks committed Jan 28, 2025
1 parent a343980 commit 285a5cc
Showing 1 changed file with 138 additions and 126 deletions.
264 changes: 138 additions & 126 deletions src/test/failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>();
Expand Down Expand Up @@ -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();

0 comments on commit 285a5cc

Please sign in to comment.