Harden traffic history worker lifecycle and query performance
Build and Deploy Gateway / build-and-push (push) Successful in 37s
Build and Deploy Gateway / deploy (push) Successful in 19s

This commit is contained in:
2026-09-19 09:58:54 +03:00
parent 74c5b66482
commit 4c58384056
14 changed files with 509 additions and 89 deletions
+46 -3
View File
@@ -143,8 +143,12 @@ test('typed endpoint facade preserves exact request contracts and raw payload id
assert.equal(await invoke(), payload);
const [actualUrl, actualOptions] = calls.at(-1);
assert.equal(actualUrl, url);
assert.deepEqual(actualOptions, {
...options,
assert.ok(actualOptions.signal instanceof AbortSignal);
assert.equal(actualOptions.signal.aborted, false);
const { signal: requestedSignal, ...requestOptions } = options;
const { signal: actualSignal, ...fetchOptions } = actualOptions;
assert.deepEqual(fetchOptions, {
...requestOptions,
headers: { 'content-type': 'application/json' },
});
}
@@ -162,7 +166,9 @@ test('request preserves caller headers, AbortError identity and JSON fallbacks',
received = [url, options];
return { ok: true, status: 200, json: async () => value };
}), value);
assert.deepEqual(received, ['/api/test', {
assert.ok(received[1].signal instanceof AbortSignal);
const { signal, ...options } = received[1];
assert.deepEqual([received[0], options], ['/api/test', {
headers: { 'content-type': 'application/custom', 'x-harbor': 'yes' },
}]);
@@ -188,3 +194,40 @@ test('request preserves caller headers, AbortError identity and JSON fallbacks',
(error) => error.code === 'CONTROL_UNREACHABLE' && error.status === 503,
);
});
test('API deadlines cover headers and response bodies, while caller cancellation keeps its reason', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });
const stalled = (signal) => new Promise((resolve, reject) => {
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
});
for (const phase of ['headers', 'body']) {
let signal;
const pending = request('/api/state', {}, async (url, options) => {
signal = options.signal;
return phase === 'headers' ? stalled(signal)
: { ok: true, status: 200, json: () => stalled(signal) };
});
const checked = assert.rejects(pending, (error) => error.code === 'CONTROL_UNREACHABLE' && error.retryable);
await Promise.resolve();
t.mock.timers.tick(14_999);
assert.equal(signal.aborted, false);
t.mock.timers.tick(1);
await checked;
}
const caller = new AbortController();
const reason = new DOMException('left the page', 'AbortError');
const pending = request('/api/test', { signal: caller.signal }, (url, options) => stalled(options.signal));
const checked = assert.rejects(pending, (error) => error === reason);
caller.abort(reason);
await checked;
let commandSignal;
const command = request('/api/diagnostics/dns', { method: 'POST' }, (url, options) => {
commandSignal = options.signal;
return stalled(commandSignal);
});
const commandChecked = assert.rejects(command, (error) => error.code === 'CONTROL_UNREACHABLE');
t.mock.timers.tick(59_999);
assert.equal(commandSignal.aborted, false);
t.mock.timers.tick(1);
await commandChecked;
});