Skip to content

Commit 2eaa1b1

Browse files
elitanclaude
andcommitted
Fix snapshot timestamp collision in tests
Add delays between branch creates that share the same parent to prevent ZFS snapshot name collisions. Snapshots use second-precision timestamps, so rapid branch creation from the same parent causes duplicate snapshot names. Also add TIMEOUTS.PITR_RECOVERY constant for semantic clarity on PITR test timeouts. Fixes: - branch-delete-force.test.ts: Add sleeps between sibling branches from same parent - helpers/wait.ts: Add TIMEOUTS.PITR_RECOVERY (180s) constant - pitr.test.ts: Use TIMEOUTS.PITR_RECOVERY instead of hardcoded 180000 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6996cd5 commit 2eaa1b1

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

tests/branch-delete-force.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ describe('Branch Delete with --force', () => {
135135
await branchCreateCommand('force-test/level2a', { parent: 'force-test/level1' });
136136
await waitForBranchReady('force-test', 'level2a');
137137

138+
// Small delay to ensure unique snapshot timestamps (snapshots use second-precision)
139+
await Bun.sleep(1000);
140+
138141
// Create level2b (child of level1)
139142
await branchCreateCommand('force-test/level2b', { parent: 'force-test/level1' });
140143
await waitForBranchReady('force-test', 'level2b');
@@ -174,7 +177,7 @@ describe('Branch Delete with --force', () => {
174177
// Only main should remain
175178
expect(project?.branches?.length).toBe(1);
176179
expect(project?.branches?.[0]?.name).toBe('force-test/main');
177-
}, { timeout: 60000 });
180+
}, { timeout: 60000 }); // Creates 4 branches, needs extra time
178181
});
179182

180183
describe('Delete branch with sibling branches', () => {
@@ -188,6 +191,9 @@ describe('Branch Delete with --force', () => {
188191
await branchCreateCommand('force-test/sibling1', {});
189192
await waitForBranchReady('force-test', 'sibling1');
190193

194+
// Small delay to ensure unique snapshot timestamps (snapshots use second-precision)
195+
await Bun.sleep(1000);
196+
191197
await branchCreateCommand('force-test/sibling2', {});
192198
await waitForBranchReady('force-test', 'sibling2');
193199

@@ -215,6 +221,6 @@ describe('Branch Delete with --force', () => {
215221
expect(project?.branches?.find((b: any) => b.name === 'force-test/sibling1')).toBeUndefined();
216222
expect(project?.branches?.find((b: any) => b.name === 'force-test/sibling1-child')).toBeUndefined();
217223
expect(project?.branches?.find((b: any) => b.name === 'force-test/sibling2')).toBeDefined();
218-
}, { timeout: 60000 });
224+
}, { timeout: 60000 }); // Creates 3 branches, needs extra time
219225
});
220226
});

tests/helpers/wait.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const TIMEOUTS = {
1515
CONTAINER_STOP: 10_000,
1616
DATASET_CREATE: 5_000,
1717
POSTGRES_READY: 60_000,
18+
PITR_RECOVERY: 180_000, // PITR recovery needs extra time for WAL replay
1819
} as const;
1920

2021
/**

tests/integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Integration Tests', () => {
6060
// Branches should be much smaller due to CoW
6161
expect(devSize).toBeLessThan(parentSize);
6262
expect(stagingSize).toBeLessThan(parentSize);
63-
}, { timeout: 60000 });
63+
}, { timeout: 60000 }); // Inserts 100 rows, needs extra time
6464
});
6565

6666
describe('State Integrity', () => {
@@ -139,6 +139,6 @@ describe('Integration Tests', () => {
139139
const project = state.projects?.find((p: any) => p.name === 'multi-test');
140140

141141
expect(project?.branches?.length).toBe(3); // main, dev, feature
142-
}, { timeout: 60000 });
142+
}, { timeout: 60000 }); // Creates multiple branches, needs extra time
143143
});
144144
});

tests/pitr.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
77
import * as cleanup from './helpers/cleanup';
88
import { getProjectCredentials, getBranchPort, query, waitForReady, ensureWALArchived } from './helpers/database';
9+
import { TIMEOUTS } from './helpers/wait';
910
import {
1011
silenceConsole,
1112
projectCreateCommand,
@@ -87,7 +88,7 @@ describe('Point-in-Time Recovery (PITR)', () => {
8788
// Should NOT have: 'after-snapshot-2' (inserted after recovery target)
8889
const count = await query(recoveryPort, creds.password, 'SELECT COUNT(*) FROM pitr_data;');
8990
expect(parseInt(count)).toBe(2);
90-
}, { timeout: 180000 }); // PITR recovery needs extra time for WAL replay
91+
}, { timeout: TIMEOUTS.PITR_RECOVERY });
9192

9293
test('should fail with PITR before any snapshots', async () => {
9394
// Try to recover to a time way in the past
@@ -107,6 +108,6 @@ describe('Point-in-Time Recovery (PITR)', () => {
107108
// Either success or failure is acceptable for this test
108109
expect(error).toBeDefined();
109110
}
110-
}, { timeout: 180000 }); // PITR recovery needs extra time for WAL replay on slower machines
111+
}, { timeout: TIMEOUTS.PITR_RECOVERY });
111112
});
112113
});

tests/wal.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('WAL Operations', () => {
3838
test('should show WAL info for all branches', async () => {
3939
await ensureSetup();
4040
await walInfoCommand(undefined);
41-
}, { timeout: 60000 }); // PostgreSQL startup + WAL archiving can take time
41+
}, { timeout: 60000 });
4242

4343
test('should show WAL info for specific branch', async () => {
4444
await ensureSetup();

0 commit comments

Comments
 (0)