commit f061cbd2f3f7bb948926f143a7157cc2c9cb51d3
parent 5fed90c02cec29c796e1327ceafd3f9afaa582e1
Author: Florian Dold <dold@taler.net>
Date: Tue, 21 Jul 2026 10:58:59 +0200
util: test that the performance table reports a real average
Diffstat:
1 file changed, 44 insertions(+), 0 deletions(-)
diff --git a/packages/taler-util/src/performance.test.ts b/packages/taler-util/src/performance.test.ts
@@ -0,0 +1,44 @@
+/*
+ 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 assert from "node:assert";
+import { test } from "node:test";
+import { ObservabilityEventType } from "./notifications.js";
+import { PerformanceStatType, PerformanceTable } from "./performance.js";
+
+function dbQuery(durationMs: number): any {
+ return {
+ type: ObservabilityEventType.DbQueryFinishSuccess,
+ name: "getCoin",
+ location: "coins.ts",
+ durationMs,
+ };
+}
+
+test("performance table averages over all samples", (t) => {
+ const tab: PerformanceTable = {};
+ for (const d of [10, 10, 10, 10, 1000]) {
+ PerformanceTable.insertEvent(tab, dbQuery(d));
+ }
+ const entries = tab[PerformanceStatType.DbQuery]!;
+ assert.strictEqual(entries.length, 1);
+ const stat = entries[0];
+ assert.strictEqual(stat.count, 5);
+ assert.strictEqual(stat.totalDurationMs, 1040);
+ assert.strictEqual(stat.minDurationMs, 10);
+ assert.strictEqual(stat.maxDurationMs, 1000);
+ assert.strictEqual(stat.avgDurationMs, 208);
+});