You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/08/27 12:18:54 UTC
(maka) branch main updated: test(runtime-host): fix flaky startup failure test via native fake timers (#3840) (#3859)
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/maka.git
The following commit(s) were added to refs/heads/main by this push:
new c8410c53b test(runtime-host): fix flaky startup failure test via native fake timers (#3840) (#3859)
c8410c53b is described below
commit c8410c53b52e1ab3d19fc1fff45c90885a853862
Author: Bryandero98 <12...@users.noreply.github.com>
AuthorDate: Thu Aug 27 07:18:49 2026 -0500
test(runtime-host): fix flaky startup failure test via native fake timers (#3840) (#3859)
The "startup failure preserves its cause when shutdown reaches the
active deadline" test in host-kernel.test.ts raced a real 100ms
shutdownGraceMs deadline against real I/O that #closeResources() must
perform before it ever calls composition.close() (registration writes,
listener admission close, storage-root identity re-validation). On a
loaded runner that pre-close bookkeeping alone can exceed 100ms,
causing #assertShutdownCanContinue() to abort the shutdown sequence
before composition.close() is ever invoked. closeEntered then never
resolves, and the test fails with "composition close did not begin" -
a false negative, since the kernel is behaving exactly as designed.
Fix: enable node:test's built-in mock timers (already used elsewhere
in this package, see gitoxide-helper-invocation-internal.test.ts) right
before starting the kernel, await the real, un-timed signal that
close() was actually entered, and only then deterministically tick the
100ms deadline forward. This reproduces the intended scenario - close()
genuinely stuck when shutdownGraceMs elapses - without racing real
wall-clock jitter, and without touching any kernel production code.
#3844 fixed the same reported flakiness by widening the two
withTimeout budgets this replaces, but that only tolerates a slow
startup chain before close() is invoked - it does not touch the
scenario above, where close() is invoked but assertShutdownCanContinue
aborts before it can return. Rebased onto main after #3844 merged;
kept its widened 5s budgets wrapping closeEntered/startupFailure as
deliberate redundancy, not a leftover - fake timers remove the jitter
they were tolerating, so they now exist only to fail fast with a named
error if this test ever regresses, instead of the generic message from
the outer 10_000ms test timeout.
Verified: 20/20 consecutive runs passing after the rebase, tsc --noEmit
clean.
Generated-by: Claude (Anthropic, Claude Code)
---
.../runtime-host/src/__tests__/host-kernel.test.ts | 35 +++++++++++++++++++---
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/packages/runtime-host/src/__tests__/host-kernel.test.ts b/packages/runtime-host/src/__tests__/host-kernel.test.ts
index 3c7e1ed0d..12774e78a 100644
--- a/packages/runtime-host/src/__tests__/host-kernel.test.ts
+++ b/packages/runtime-host/src/__tests__/host-kernel.test.ts
@@ -1420,7 +1420,9 @@ describe('non-serving Runtime Host kernel', () => {
});
});
- test('startup failure preserves its cause when shutdown reaches the active deadline', async () => {
+ test('startup failure preserves its cause when shutdown reaches the active deadline', {
+ timeout: 10_000,
+ }, async (t) => {
await withHostPaths(async (paths) => {
const capability = await resolveStorageRoot({ path: paths.root, kind: 'interactive' });
const owner = await tryAcquireInteractiveRootOwner(capability);
@@ -1434,6 +1436,19 @@ describe('non-serving Runtime Host kernel', () => {
releaseClose = resolve;
});
const lifecycle: string[] = [];
+
+ // Fake timers isolate the shutdownGraceMs deadline from real I/O jitter
+ // (registration writes, listener admission, storage-root binding) that
+ // #closeResources() performs before it ever calls composition.close().
+ // On a loaded runner that real work alone can exceed a real 100ms
+ // deadline, aborting shutdown via #assertShutdownCanContinue() before
+ // close() is entered at all — closeEntered then never resolves, and the
+ // test fails with "composition close did not begin" despite the kernel
+ // behaving correctly. Enabling mock timers only after `owner` is already
+ // acquired keeps the earlier real lock-acquisition path (which does poll
+ // via a real setTimeout in @maka/storage's file-update-lock) unaffected.
+ t.mock.timers.enable({ apis: ['setTimeout'] });
+
const hostTask = RuntimeHostKernel.start({
owner,
idleGraceMs: 10_000,
@@ -1460,10 +1475,22 @@ describe('non-serving Runtime Host kernel', () => {
);
try {
- // The storage/owner/drain chain before the close hook can exceed 1s
- // on loaded CI runners (see #3840); tolerate that without weakening
- // shutdownGraceMs, which still exercises the active-deadline path.
+ // #3844 widened these budgets to tolerate real wall-clock jitter on a
+ // loaded runner (see #3840). Fake timers remove that jitter, so these
+ // withTimeout wrappers no longer tolerate anything real - they are
+ // deliberate redundancy, kept only so a genuine regression (close()
+ // never entered, or startupFailure never settling after the tick)
+ // fails fast with a named error instead of the generic message from
+ // the outer 10_000ms test timeout.
await withTimeout(closeEntered, 5_000, 'composition close did not begin');
+ // Deliberately fire the shutdown deadline now that close() is
+ // confirmed to be genuinely stuck on closeReleased - the exact
+ // scenario this test exists to exercise, reproduced deterministically
+ // instead of raced against wall-clock jitter.
+ t.mock.timers.tick(100);
+ // Let the promise chain settle after the synchronous timer callback
+ // (same pattern as gitoxide-helper-invocation-internal.test.ts).
+ await new Promise<void>((resolve) => setImmediate(resolve));
const error = await withTimeout(
startupFailure,
5_000,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org