Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: freeze scheduling delay when diagnostic sampling stops
Adam Eivy25ac0494e846
diff --git a/server/test/dbPhaseDiagnostics.js b/server/test/dbPhaseDiagnostics.jsindex daf9506b4c..ba79e28a6f 100644--- a/server/test/dbPhaseDiagnostics.js+++ b/server/test/dbPhaseDiagnostics.js@@ -71,7 +71,13 @@ export function createDbPhaseDiagnostics({ onTestFailed, observer, fixturePid, esample(active, count);}, intervalMs);timer.unref?.();- active.stop = () => clearInterval(timer);+ active.stop = () => {+ // Cancellation stops the timer deliberately; later body-drain time+ // must not be reported as an event-loop scheduling delay.+ active.timerDelayMs = metrics().timerDelayMs;+ active.nextSampleAt = Infinity;+ clearInterval(timer);+ };try { return await operation(); }finally {clearInterval(timer);diff --git a/server/test/dbPhaseDiagnostics.test.js b/server/test/dbPhaseDiagnostics.test.jsindex 6ca51ee4a8..11a3aa2f07 100644--- a/server/test/dbPhaseDiagnostics.test.js+++ b/server/test/dbPhaseDiagnostics.test.js@@ -61,8 +61,9 @@ it('retains late waits and timer delay at failure without sampling cancelled worconst observer = { query: vi.fn(async () => ({ rows: [{ fixture: true,wait_event_type: now >= 10000 ? 'Lock' : null, wait_event: now >= 10000 ? 'relation' : null }] })) };const operation = Promise.withResolvers();+ const lines = [];const diagnostics = createDbPhaseDiagnostics({ onTestFailed: hook => hooks.push(hook), observer,- fixturePid: 42, enabled: true, write: () => {} });+ fixturePid: 42, enabled: true, write: line => lines.push(line) });expect(await diagnostics.phase('fast-fixture', () => 'original result')).toBe('original result');expect(observer.query).not.toHaveBeenCalled();const run = diagnostics.phase('compact-explain', () => operation.promise);@@ -82,10 +83,15 @@ it('retains late waits and timer delay at failure without sampling cancelled worexpect(error.message).toContain('"timerDelayMs":10000');expect(error.message).toContain('"wait_event":"relation"');expect(error.message).toContain('"phase":"compact-explain"');+ now = 64000;await vi.advanceTimersByTimeAsync(50000);expect(observer.query).toHaveBeenCalledTimes(4);operation.resolve();await run;+ // Teardown waiting on the body after cancellation is not scheduler delay.+ const settled = lines.map(line => JSON.parse(line.slice('DB phases: '.length)))+ .find(event => event.phase === 'compact-explain' && event.state === 'settled');+ expect(settled.timerDelayMs).toBe(10000);await diagnostics.phase('after-cancellation', () => undefined);await diagnostics.drain();expect(observer.query).toHaveBeenCalledTimes(4);