Skip to content

Commit 1c0a5de

Browse files
jchrisclaude
andcommitted
fix: resolve test infrastructure issues for meta corruption investigation
- Fixed undefined subscriptionCounts and receivedDocs variables in offline sync test - Added proper subscription tracking infrastructure for sync tests - Cleaned up ESLint issues and type errors - Offline sync test now passes, allowing focus on the main corruption issue The main "should trigger subscriptions on inbound syncing" test continues to fail with the actual meta corruption problem: - Stale CAR files (missing car file errors) - Missing blocks when CRDT clock references unavailable storage - Race conditions in attachment process where carLog shows 0 length after attach This provides a stable baseline for investigating the root cause of meta synchronization issues in distributed database scenarios. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent fc717b7 commit 1c0a5de

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

core/tests/fireproof/attachable-subscription.test.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,17 @@ describe("Remote Sync Subscription Tests", () => {
331331
});
332332

333333
describe("sync", () => {
334+
// Track subscription events for sync tests
335+
const subscriptionCounts = new Map<string, number>();
336+
const receivedDocs = new Map<string, DocWithId<string>[]>();
337+
let subscriptionCallbacks: (() => void)[] = [];
338+
334339
beforeEach(async () => {
335340
// Reset subscription tracking for each sync test
336-
// subscriptionCallbacks.forEach((unsub) => unsub());
337-
// subscriptionCallbacks = [];
338-
// // subscriptionCounts.clear();
339-
// receivedDocs.clear();
341+
subscriptionCallbacks.forEach((unsub) => unsub());
342+
subscriptionCallbacks = [];
343+
subscriptionCounts.clear();
344+
receivedDocs.clear();
340345
});
341346

342347
it("should trigger subscriptions during offline sync reconnection", async () => {
@@ -401,18 +406,26 @@ describe("Remote Sync Subscription Tests", () => {
401406
const inbound = await syncDb(`inbound-db-${id}`, `memory://sync-inbound`);
402407

403408
// Setup subscription BEFORE attaching - this simulates useLiveQuery being active
404-
const subscriptionPromise = setupSubscription(inbound);
409+
const dbKey = "inbound-db";
410+
subscriptionCounts.set(dbKey, 0);
411+
receivedDocs.set(dbKey, []);
412+
413+
const unsub = inbound.subscribe<string>((sdocs) => {
414+
const currentCount = subscriptionCounts.get(dbKey) || 0;
415+
subscriptionCounts.set(dbKey, currentCount + 1);
416+
417+
const currentDocs = receivedDocs.get(dbKey) || [];
418+
currentDocs.push(...sdocs);
419+
receivedDocs.set(dbKey, currentDocs);
420+
}, true);
421+
subscriptionCallbacks.push(unsub);
405422

406423
// Attach to the same sync namespace - this simulates toCloud() reconnection
407424
// 🐛 BUG: This should trigger subscription but doesn't
408425
await inbound.attach(aJoinable(`sync-${id}`, inbound));
409426

410-
// Wait for subscription to fire (or timeout)
411-
// 🐛 BUG: This will timeout because subscription never fires for reconnection sync
412-
await Promise.race([
413-
subscriptionPromise,
414-
new Promise((_, reject) => setTimeout(() => reject(new Error("Subscription timeout")), 5000)),
415-
]);
427+
// Wait for sync to complete - give time for subscription to fire
428+
await new Promise(resolve => setTimeout(resolve, 1000));
416429

417430
// Verify the subscription was triggered by remote sync
418431
expect(subscriptionCounts.get("inbound-db")).toBeGreaterThan(0);

0 commit comments

Comments
 (0)