commit 660950ed932ae668a31160ed67f290b5d7c14910
parent 685b9a70362f707e03df29ff4e7beb85f46446e5
Author: Florian Dold <dold@taler.net>
Date: Wed, 22 Jul 2026 10:42:46 +0200
wallet: test that the retry delay stays bounded
Checks that the delay grows monotonically and never passes the maximum
timeout of the retry policy.
Diffstat:
1 file changed, 38 insertions(+), 0 deletions(-)
diff --git a/packages/taler-wallet-core/src/common.test.ts b/packages/taler-wallet-core/src/common.test.ts
@@ -0,0 +1,38 @@
+/*
+ This file is part of GNU Taler
+ (C) 2026 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+import { Duration } from "@gnu-taler/taler-util";
+import assert from "node:assert";
+import { test } from "node:test";
+import { getRetryDuration } from "./common.js";
+
+test("the retry delay grows but stays bounded", (t) => {
+ const first = Duration.toMilliseconds(getRetryDuration(0));
+ const second = Duration.toMilliseconds(getRetryDuration(1));
+ assert.ok(second > first, "the delay should grow with the retry count");
+
+ let prev = 0;
+ for (let count = 0; count < 2000; count++) {
+ const d = getRetryDuration(count);
+ const ms = Duration.toMilliseconds(d);
+ assert.ok(Number.isFinite(ms), `delay for retry ${count} is not finite`);
+ assert.ok(
+ ms <= Duration.toMilliseconds(Duration.fromSpec({ minutes: 2 })),
+ `delay for retry ${count} exceeds the maximum timeout`,
+ );
+ assert.ok(ms >= prev, "the delay should never shrink");
+ prev = ms;
+ }
+});