Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(sync): the #7355 level-progress and #6543 live-blocker drain cases run on the drain's injected clock and a probe count, not real-time windows a stalled event loop overran

garrytan1546460442bf
diff --git a/test/sync-drain-head-blocked-6543.test.ts b/test/sync-drain-head-blocked-6543.test.ts
index b7e227580e..f8dd52f76d 100644
--- a/test/sync-drain-head-blocked-6543.test.ts
+++ b/test/sync-drain-head-blocked-6543.test.ts
@@ -54,10 +54,10 @@ describe('in-pass governor: head blocker classification', () => {
});
test('a live blocker (a foreground publication ahead) lasting several ticks never stops the drain; the pass completes', async () => {
- let reads = 0;
+ let reads = 0, finish!: () => void;
const result = await runDrain({ governMs: 10, noProgressMs: 60_000, publicationCeilingMs: 60_000,
- probe: probeWith(async () => { reads++; return { head_state: 'queued', request_id: 'req-head', claim: null, claimable_here: false, blocked_by: hold }; }),
- pass: () => new Promise<SyncResult>(resolve => setTimeout(() => resolve({ ...done, managedCursor: { index: 1, total: 1 } }), 150)) });
+ probe: probeWith(async () => { if (++reads === 3) finish(); return { head_state: 'queued', request_id: 'req-head', claim: null, claimable_here: false, blocked_by: hold }; }),
+ pass: () => new Promise<SyncResult>(resolve => { finish = () => setTimeout(() => resolve({ ...done, managedCursor: { index: 1, total: 1 } }), 20); }) });
expect(reads).toBeGreaterThanOrEqual(3);
expect(result.drain).toMatchObject({ outcome: 'synced' });
});
diff --git a/test/sync-pass-abandoned-7355.test.ts b/test/sync-pass-abandoned-7355.test.ts
index 14b4a0ad88..b3606bbcf1 100644
--- a/test/sync-pass-abandoned-7355.test.ts
+++ b/test/sync-pass-abandoned-7355.test.ts
@@ -43,10 +43,18 @@ function repo(): string {
}
describe('#7355: the drain hears a level read that is still working', () => {
+ // The drain's clock advances 20 ms per level-progress event against an 80 ms window, so the verdict no longer depends on
+ // event-loop scheduling (a loaded runner stalled the loop past the window). The governor still ticks on real timers; the
+ // 120 ms loop stall after the first event outlasts the window on purpose and stopped the pass before the clock seam.
test('a pass that reports level progress past the no-progress window is not abandoned', async () => {
- const result = await runDrain({ governMs: 10, noProgressMs: 80, publicationCeilingMs: 60_000,
+ let now = 0;
+ const result = await runDrain({ governMs: 10, noProgressMs: 80, publicationCeilingMs: 60_000, clock: () => now,
pass: async (_signal, onProgress) => {
- for (let i = 0; i < 20; i++) { onProgress?.({ phase: 'managed_sync.level_progress' }); await Bun.sleep(20); }
+ for (let i = 0; i < 20; i++) {
+ onProgress?.({ phase: 'managed_sync.level_progress' }); now += 20;
+ if (i === 0) { const blockedUntil = performance.now() + 120; while (performance.now() < blockedUntil) { /* the event loop stalls 120 ms after the first event */ } }
+ await Bun.sleep(20);
+ }
return done;
} });
expect(result.drain).toMatchObject({ outcome: 'synced', passes: 1 });