commit b35eeaea94a2260d27924bd88c35a1ddbb1020c3
parent 1ad4449348088db15c243c7cb2d0d5170b337c50
Author: Florian Dold <dold@taler.net>
Date: Tue, 21 Jul 2026 10:59:48 +0200
util: test the long-polling flag on observability events
Diffstat:
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/packages/taler-util/src/observability.test.ts b/packages/taler-util/src/observability.test.ts
@@ -52,3 +52,29 @@ test("ObservableHttpClientLibrary releases the caller's cancellation callback",
// long-lived token, not leave one behind per request.
assert.strictEqual(callbacks().size, 0);
});
+
+test("ObservableHttpClientLibrary reports long polling consistently", async (t) => {
+ const events: any[] = [];
+ const inner: HttpRequestLibrary = {
+ fetch: async (url) => stubResponse(url),
+ };
+ const client = new ObservableHttpClientLibrary(inner, {
+ observe: (evt) => events.push(evt),
+ });
+ const source = CancellationToken.create();
+
+ const opts = { cancellationToken: source.token };
+ await client.fetch("http://example.com/", opts);
+ await client.fetch("http://example.com/plain");
+
+ // A request the caller supplied a cancellation token for is the long poll;
+ // the start and the finish event of one request must agree.
+ const [pollStart, pollEnd, plainStart, plainEnd] = events;
+ assert.strictEqual(pollStart.longPolling, true);
+ assert.strictEqual(pollEnd.longPolling, true);
+ assert.strictEqual(plainStart.longPolling, false);
+ assert.strictEqual(plainEnd.longPolling, false);
+
+ // The caller's options object must not be rewritten.
+ assert.strictEqual(opts.cancellationToken, source.token);
+});