Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(persistence): the two-consumer drain test waits for the CLI consumer to settle before admitting (forced probe: a delayed first probe fails before, passes after)

time-attackfc6d454b1651
diff --git a/test/e2e/persistence-two-consumers-postgres.test.ts b/test/e2e/persistence-two-consumers-postgres.test.ts
index 58c0557e1e..ceaf30ecd0 100644
--- a/test/e2e/persistence-two-consumers-postgres.test.ts
+++ b/test/e2e/persistence-two-consumers-postgres.test.ts
@@ -30,7 +30,7 @@ import { consumerIdentity, listHostConsumers, resetConsumerIdentityForTest, star
import { claimOwner, setClaimOwnerForTest } from '../../src/core/persistence/claim-phase.ts';
import { localHostIdentity } from '../../src/core/persistence/identity.ts';
import { claimWorktree } from '../../src/core/persistence/ownership.ts';
-import { disposePersistenceConsumer, persistenceConsumerStatus, preparePersistedMutation } from '../../src/core/persistence/service.ts';
+import { disposePersistenceConsumer, persistenceConsumerStatus, preparePersistedMutation, startPersistenceConsumer } from '../../src/core/persistence/service.ts';
import { resetWriteSwitches } from '../../src/core/persistence/switches.ts';
import { performSync } from '../../src/commands/sync/perform.ts';
import { twoConsumersOnHostCheck } from '../../src/commands/doctor/checks/persistence-consumers.ts';
@@ -118,6 +118,12 @@ describe.skipIf(!hasDatabase())('two consumers on one host (Postgres, #6317)', (
try {
await waitFor(async () => (await listHostConsumers(engine, hostId)).some(row => row.pid === serve.pid && row.kind === 'serve' && row.mode === 'full'), { timeoutMs: 30_000, intervalMs: 200, label: 'the serve writes its heartbeat row' });
const f = await fixture(100);
+ // The CLI's consumer settles before the drain admits anything: while it still probes it claims nothing, and a
+ // fast serve could publish all 100 first. Its election is what this test pins, not that race.
+ startPersistenceConsumer(engine, { engine: 'postgres' });
+ const settled = single ? 'waiter_only' : 'full';
+ await waitFor(async () => (persistenceConsumerStatus(engine) as { consumer_election?: { mode: string } }).consumer_election?.mode === settled,
+ { timeoutMs: 30_000, intervalMs: 50, label: `the CLI consumer settles to ${settled}` });
const result = await performSync(engine, { sourceId: f.id, noPull: true, noEmbed: true, noExtract: true, drain: true, lanes: 4 });
expect(result.drain?.outcome).toBe('synced');
const rows = await imports(f.id);