Skip to content

Commit 6497cf7

Browse files
mchwangclaude
andcommitted
The racer shim acts only on its own allocation's create (#189)
Review round 35: should a race test time out with the shim on PATH, other tests' creates pass through; withoutRunnerLabel's doc says what a wrapper left on PATH does to a later test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 26e9103 commit 6497cf7

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎test/agent-container.test.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,9 @@ describe('real Docker agent isolation', () => {
704704
// holds one of this run's volumes or networks, and such a volume or network never, so the wrapper labels it with a
705705
// test-run ID and this file's run ID instead (#189). Whatever has that ID is removed when the test finishes (Vitest
706706
// runs `onTestFinished` after a pass, a failure or a timeout; the `it.fails` pair below tests the failure), and again
707-
// in afterAll, for a create that lands after a timed-out test's removal (its body runs on).
707+
// in afterAll, for a create that lands after a timed-out test's removal (its body runs on). A timed-out test leaves the
708+
// wrapper on PATH while its body runs on, so a later test's matching create is unlabelled too and that test fails;
709+
// what it makes carries this file's run ID, so afterAll removes it.
708710
const withoutRunnerLabel = async <T>(prefixes: string[][], run: () => Promise<T> | T): Promise<T> => {
709711
if (!prefixes.every(prefix => prefix.includes('create'))) throw new Error('Only create commands can be unlabelled.');
710712
const testRun = randomUUID();
@@ -913,18 +915,19 @@ describe('real Docker agent isolation', () => {
913915
try { return await run(); } finally { process.env.PATH = path; }
914916
};
915917
// After our create, another process creates a volume carrying the same allocation ID: both passed the check first.
916-
const racer = (name: string) => [
918+
// Only for this allocation's create: should the test time out with the shim still on PATH, other creates pass through.
919+
const racer = (name: string, allocationId: string) => [
917920
'result = run(args);',
918-
"const allocation = args.find(arg => arg.startsWith('io.codeboost.allocation='));",
919-
`run(['volume', 'create', '--label', 'io.codeboost.runner=${'f'.repeat(32)}', '--label', allocation, '${name}']);`,
921+
`if (args.includes('io.codeboost.allocation=${allocationId}'))`,
922+
` run(['volume', 'create', '--label', 'io.codeboost.runner=${'f'.repeat(32)}', '--label', 'io.codeboost.allocation=${allocationId}', '${name}']);`,
920923
].join('\n');
921924

922925
it('backs out of task storage when a concurrent process claims the same allocation ID', async () => {
923926
const data = fixture(), owner = testOwner('storage-race'), rival = `codeboost-race-${randomUUID()}`;
924927
// Tracked for afterAll should the test time out: the rival carries another runner's label (#189).
925928
volumes.add(rival);
926929
try {
927-
await withDockerShim(['volume', 'create'], racer(rival), () => expect(() => prepareTaskFilesystems(data.clone,
930+
await withDockerShim(['volume', 'create'], racer(rival, owner.allocationId), () => expect(() => prepareTaskFilesystems(data.clone,
928931
{ workBytes: 16 * 1024 * 1024, workInodes: 512, metadataBytes: 16 * 1024 * 1024, metadataInodes: 512 },
929932
imageId, owner)).toThrow('still labels a Docker object'));
930933
expect(byAllocation(owner.allocationId)).toEqual([rival]);
@@ -936,7 +939,7 @@ describe('real Docker agent isolation', () => {
936939
// Tracked for afterAll should the test time out: the rival carries another runner's label (#189).
937940
volumes.add(rival);
938941
try {
939-
await withDockerShim(['network', 'create'], racer(rival), () => expect(createVendorNetwork(
942+
await withDockerShim(['network', 'create'], racer(rival, allocationId), () => expect(createVendorNetwork(
940943
invocation(data.clone, 'planning'), imageId, allocationId)).rejects.toThrow('still labels a Docker object'));
941944
expect(byAllocation(allocationId)).toEqual([rival]);
942945
} finally { spawnSync('docker', ['volume', 'rm', '--force', rival], { stdio: 'ignore' }); }

0 commit comments

Comments
 (0)