taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit fddafb9fc9b6934b8840e1487eef1c28dd6b1502
parent 36c201fbc464667ec1b5b6f1a291cdbf69222f3b
Author: Florian Dold <dold@taler.net>
Date:   Tue, 21 Jul 2026 11:02:06 +0200

util: test that resolveAfter settles when the group is stopped

Diffstat:
Mpackages/taler-util/src/timer.test.ts | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/packages/taler-util/src/timer.test.ts b/packages/taler-util/src/timer.test.ts @@ -68,3 +68,29 @@ test("resolveAfter does not schedule when already cancelled", async (t) => { assert.strictEqual(res, false); assert.strictEqual(trackedTimers(tg), 0); }); + +/** + * Resolve to "pending" if the promise has not settled within a few ticks. + */ +async function settledWithin<T>( + p: Promise<T>, + ms: number, +): Promise<T | "pending"> { + return Promise.race([ + p, + new Promise<"pending">((r) => setTimeout(() => r("pending"), ms)), + ]); +} + +test("resolveAfter settles when the timer group is stopped", async (t) => { + const tg = new TimerGroup(new SetTimeoutTimerAPI()); + const inFlight = tg.resolveAfter(Duration.fromMilliseconds(60000)); + tg.stopCurrentAndFutureTimers(); + assert.strictEqual(await settledWithin(inFlight, 50), false); + + // A wait started after the shutdown must not hang either. + assert.strictEqual( + await settledWithin(tg.resolveAfter(Duration.fromMilliseconds(60000)), 50), + false, + ); +});