Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions listener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"test": "node ./node_modules/jest/bin/jest.js",
"migrate": "ts-node src/scripts/migrate-db.ts",
"migrate:templates": "ts-node src/scripts/migrate-templates.ts",
"typecheck": "node ./node_modules/typescript/bin/tsc --noEmit",
"lint": "node ./node_modules/typescript/bin/tsc --noEmit",
"check-migrations": "ts-node src/scripts/check-migrations.ts",
"validate:batch": "ts-node src/utils/batch-validator.ts"
},
Expand Down
25 changes: 25 additions & 0 deletions listener/src/__tests__/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,29 @@ describe("Full Notification Lifecycle Integration Test", () => {
// 5. Simulate acknowledgement (event is processed)
expect(retrievedEvents[0].receivedAt).toBeLessThanOrEqual(Date.now());
});

test("evicts oldest events instead of failing when registry is at capacity", () => {
const boundedRegistry = new EventRegistry(2);
const topic = [xdr.ScVal.scvSymbol("task"), xdr.ScVal.scvSymbol("created")];
const value = xdr.ScVal.scvU32(1);

for (let i = 0; i < 3; i++) {
boundedRegistry.addFromInput({
eventId: `event-${i}`,
contractAddress: "CDNJ3YJ5F4U5YF4O5U6Y7I8U9Y0U1I2O3P4I5U6Y7I8",
eventName: "task",
ledger: 100 + i,
type: "contract",
topic,
value,
txHash: `hash-${i}`,
});
}

// The registry should degrade gracefully (evict oldest) rather than
// throwing or silently dropping the newest notification.
const remaining = boundedRegistry.getEvents();
expect(remaining.length).toBe(2);
expect(remaining.map((e) => e.eventId)).toEqual(["event-1", "event-2"]);
});
});
6 changes: 2 additions & 4 deletions listener/src/store/event-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export class EventRegistry {
this.cleanupTimer = setInterval(() => this.pruneExpired(), intervalMs);
}

setTtlMs(ms: number): void {
this.ttlMs = ms;
}

stopCleanup(): void {
if (this.cleanupTimer) {
clearInterval(this.cleanupTimer);
Expand Down Expand Up @@ -119,3 +115,5 @@ export class EventRegistry {
}

export const eventRegistry = new EventRegistry();