Skip to content

Commit 61382f5

Browse files
committed
test(action-ledger): release late-registered cleanup resolvers in failure teardown
Autoreview: after the finally block drains the resolver array, a queued blocked post can still start and register a new stuck cleanup on a later microtask, hanging the flush. Gate the mock on a release flag so any cancel after teardown begins resolves immediately.
1 parent 8aa2e12 commit 61382f5

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎test/action-ledger-runtime.test.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,15 +3258,18 @@ test("cleanup-stuck projection rejection is scoped to the affected spool root",
32583258
CLAWSWEEPER_CRABFLEET_TIMEOUT_MS: "30000",
32593259
});
32603260
const cleanupResolvers: Array<() => void> = [];
3261+
let releaseCleanups = false;
32613262
const blockedFetch = (async () =>
32623263
({
32633264
ok: true,
32643265
status: 204,
32653266
body: {
32663267
cancel: () =>
3267-
new Promise<void>((resolve) => {
3268-
cleanupResolvers.push(resolve);
3269-
}),
3268+
releaseCleanups
3269+
? Promise.resolve()
3270+
: new Promise<void>((resolve) => {
3271+
cleanupResolvers.push(resolve);
3272+
}),
32703273
},
32713274
}) as unknown as Response) as typeof fetch;
32723275
for (let index = 0; index < CRABFLEET_PROJECTION_LIMITS.maxConcurrent + 1; index += 1) {
@@ -3301,7 +3304,9 @@ test("cleanup-stuck projection rejection is scoped to the affected spool root",
33013304
}
33023305
} finally {
33033306
// Release held slots even on failure so later tests do not inherit a starved pool.
3304-
for (const resolve of cleanupResolvers) resolve();
3307+
// The flag makes any cleanup registered after this point resolve immediately.
3308+
releaseCleanups = true;
3309+
while (cleanupResolvers.length > 0) cleanupResolvers.shift()!();
33053310
await flushPendingCrabFleetPosts();
33063311
}
33073312
assert.equal(independentStarted, 1);

0 commit comments

Comments
 (0)