|
1 | 1 | import assert from 'node:assert/strict'; |
2 | 2 | import http from 'node:http'; |
3 | | -import { test } from 'vitest'; |
| 3 | +import { test, vi } from 'vitest'; |
4 | 4 | import { AppError } from '@agent-device/kernel/errors'; |
5 | 5 | import { |
6 | 6 | DAEMON_HTTP_INSTANCE_HEADER, |
@@ -222,6 +222,35 @@ test('a delayed restart health probe stops at the RPC deadline without retrying' |
222 | 222 | } |
223 | 223 | }); |
224 | 224 |
|
| 225 | +test('a restart health probe that times out just before the RPC deadline still reports the deadline', async (t) => { |
| 226 | + if (await skipWhenLoopbackUnavailable(t)) return; |
| 227 | + let probing = false; |
| 228 | + const realNow = performance.now.bind(performance); |
| 229 | + const server = http.createServer((req, res) => { |
| 230 | + if (req.url === '/health') { |
| 231 | + probing = true; |
| 232 | + return; |
| 233 | + } |
| 234 | + res.statusCode = 409; |
| 235 | + res.setHeader(DAEMON_HTTP_INSTANCE_MISMATCH_HEADER, 'true'); |
| 236 | + res.end(); |
| 237 | + }); |
| 238 | + const clock = vi |
| 239 | + .spyOn(performance, 'now') |
| 240 | + .mockImplementation(() => realNow() - (probing ? 2 : 0)); |
| 241 | + try { |
| 242 | + const port = await listenOnLoopback(server); |
| 243 | + await assert.rejects( |
| 244 | + sendWithStaleInstance(port, 150), |
| 245 | + (error: unknown) => |
| 246 | + error instanceof AppError && error.details?.reason === 'daemon_transport_timeout', |
| 247 | + ); |
| 248 | + } finally { |
| 249 | + clock.mockRestore(); |
| 250 | + await closeLoopbackServer(server); |
| 251 | + } |
| 252 | +}); |
| 253 | + |
225 | 254 | test('proxy forwards cached upstream identity and rejects a restarted upstream before dispatch', async (t) => { |
226 | 255 | if (await skipWhenLoopbackUnavailable(t)) return; |
227 | 256 | let upstreamInstance = 'upstream-one'; |
|
0 commit comments