Skip to content

Commit 29744c7

Browse files
mchwangclaude
andcommitted
Track the peer, stand-in proxy and foreign keeper by name; holder test asserts the quiet sweep on the daemon (#189)
Review round 40: three label-less or foreign containers made with a 60 s client could land after their test's finally, and once their network is gone none is a holder, so each is tracked by name for afterAll; the holder test checks the daemon's own answer for a gone container and that the sweep reports no failure for it; the holder fake says what it leaves out; the unit file unstubs env after each test; agent-network removes its records before the sweeps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ab215c6 commit 29744c7

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎test/agent-container.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ describe('real Docker agent isolation', () => {
821821
{ encoding: 'utf8' });
822822
expect(partial.status).not.toBe(0);
823823
expect(partial.stdout).toContain(holders[0]);
824+
expect(partial.stderr).toMatch(/^Error response from daemon: No such container: codeboost-gone-/m);
824825
// The holders' inspect also names a container that does not exist, as one gone since the listing would be: Docker
825826
// 27.4 prints the others and exits 1, and the sweep must still remove them.
826827
const shim = mkdtempSync(join(tmpdir(), 'codeboost-sweep-docker-')); roots.push(shim);
@@ -829,7 +830,10 @@ describe('real Docker agent isolation', () => {
829830
writeFileSync(join(shim, 'docker'), ['#!/bin/sh',
830831
`if [ "$1 $2" = "container inspect" ]; then exec '${realDocker}' "$@" codeboost-gone-${randomUUID()}; fi`,
831832
`exec '${realDocker}' "$@"`].join('\n'), { mode: 0o755 });
832-
removeLabelledObjects(TEST_RUN_LABEL, run, 'test', join(shim, 'docker'));
833+
// And it says nothing of that gone holder: Docker's own answer is not a failure.
834+
const sweepWarn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
835+
try { removeLabelledObjects(TEST_RUN_LABEL, run, 'test', join(shim, 'docker')); } finally { sweepWarn.mockRestore(); }
836+
expect(sweepWarn.mock.calls.filter(call => String(call[0]).endsWith('failed:'))).toEqual([]);
833837
// afterAll removes tracked names with removeByName, as here: an object of exactly that name goes, and a name that
834838
// is gone says nothing.
835839
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
@@ -2549,6 +2553,8 @@ describe('real Docker agent isolation', () => {
25492553
const data = fixture(), filesystems = data.filesystems, owner = taskFilesystemOwner(filesystems);
25502554
taskFilesystems.splice(taskFilesystems.indexOf(filesystems), 1);
25512555
docker('rm', '--force', filesystems.keeper);
2556+
// Tracked for afterAll too: its create may land after the finally (#189).
2557+
containers.add(filesystems.keeper);
25522558
try {
25532559
// Inside the try: this keeper carries another runner's label, so only the finally below removes it (#189).
25542560
docker('run', '--detach', '--name', filesystems.keeper, '--label', `io.codeboost.runner=${'f'.repeat(32)}`,

‎test/agent-network.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ afterAll(async () => {
6464
// carry this file's run ID; the tests remove their own, and the try above removes those registered in
6565
// `unlabelled`. It may not run before a hook timeout. The hook's 13 minutes leave two over the worst case of these
6666
// two sweeps (eleven calls of 30 s each), for the cleanup before them.
67+
// The records were read above; removed first, so a hook timeout during the sweeps does not leave them.
68+
if (records) rmSync(records, { recursive: true, force: true });
6769
removeLabelledObjects(TEST_FILE_LABEL, TEST_FILE_RUN, 'afterAll');
6870
removeRunnerObjects(TEST_RUNNER_OWNER);
69-
if (records) rmSync(records, { recursive: true, force: true });
7071
}
7172
}, 13 * 60_000);
7273

@@ -332,6 +333,8 @@ describe('vendor-only egress', () => {
332333
const otherInvocation = captureInvocation({ ...invocation, attemptId: 'concurrent-network-probe',
333334
deadline: Date.now() + 60_000 });
334335
const other = await createVendorNetwork(otherInvocation, imageId, randomUUID()), peer = `codeboost-peer-${randomUUID()}`;
336+
// Tracked for afterAll: its create may land after the finally, and once the network is gone it is no holder (#189).
337+
unlabelled.push({ kind: 'container', name: peer });
335338
try {
336339
docker('run', '--detach', '--name', peer, `--network=${network.name}`, '--network-alias', 'codeboost-peer',
337340
'--entrypoint', 'node', imageId, '-e', "require('node:net').createServer(()=>{}).listen(4567,'0.0.0.0');setInterval(()=>{},1000)");
@@ -366,6 +369,8 @@ describe('vendor-only egress', () => {
366369
{ Config: { Labels: Record<string, string> }; NetworkSettings: { Networks: Record<string, { IPAddress: string }> } };
367370
const allocation = inspected.Config.Labels['io.codeboost.egress'];
368371
const proxyIp = inspected.NetworkSettings.Networks[replacement.name]!.IPAddress;
372+
// Tracked for afterAll: the stand-in has no runner label, and its create may land after the finally (#189).
373+
unlabelled.push({ kind: 'container', name: replacement.proxyContainer });
369374
try {
370375
docker('rm', '--force', replacement.proxyContainer);
371376
// Same name, label, image, lockdown and IP as the original, so only the extra option and the object ID differ.

‎test/docker-sweep.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const roots: string[] = [];
1616
afterEach(() => {
1717
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
1818
vi.restoreAllMocks();
19+
vi.unstubAllEnvs();
1920
});
2021

2122
// The fake answers as no real daemon does for `network ls`: a line that is not JSON, a JSON null and one network
@@ -146,7 +147,9 @@ it.each([
146147
const calls = join(root, 'calls'), net = 'n'.repeat(64), a = 'a'.repeat(64), b = 'b'.repeat(64);
147148
// Answers as Docker 27.4 does for one swept network with two candidate holders, one gone before the inspect: the
148149
// inspect prints the other and exits 1. Every other call gets no output and exit 0, as for `ls` with no match; the
149-
// removals' stdout (the removed IDs or names in 27.4) is not read.
150+
// removals' stdout (the removed IDs or names in 27.4) is not read. The network line holds only the fields the sweep
151+
// reads (27.4 also prints CreatedAt, Driver, IPv6, Internal, Labels and Scope), and the inspect an empty endpoint for
152+
// the network, where 27.4 gives its full settings: the sweep reads only the network names.
150153
writeFileSync(join(root, 'docker'), ['#!/bin/sh', `printf '%s\\n' "$*" >> '${calls}'`,
151154
`if [ "$1 $2" = "network ls" ]; then printf '%s\\n' '{"ID":"${net}","Name":"swept"}'; exit 0; fi`,
152155
`if [ "$1" = ps ]; then printf '%s\\n' ${a} ${b}; exit 0; fi`,

0 commit comments

Comments
 (0)