fix(ipintelligence): apply configured timeout to MMDB downloads and expose IP intelligence timeout option

This commit is contained in:
2026-05-21 01:42:48 +00:00
parent 23df951023
commit 8a4f756fef
4 changed files with 56 additions and 9 deletions
+26
View File
@@ -99,6 +99,32 @@ tap.test('should use cache when cacheTtl is set', async () => {
await cached.stop();
});
tap.test('should apply timeout to IP intelligence MMDB downloads', async () => {
const originalFetch = globalThis.fetch;
let sawAbort = false;
globalThis.fetch = (async (_url: RequestInfo | URL, init?: RequestInit) => {
return await new Promise<Response>((_resolve, reject) => {
init?.signal?.addEventListener('abort', () => {
sawAbort = true;
reject(new Error('aborted'));
}, { once: true });
});
}) as typeof fetch;
const intelligence = new smartnetwork.IpIntelligence({ timeout: 10 });
let caught: Error | undefined;
try {
await (intelligence as any).fetchBuffer('https://example.com/test.mmdb');
} catch (error) {
caught = error as Error;
} finally {
globalThis.fetch = originalFetch;
}
expect(sawAbort).toEqual(true);
expect(caught).toBeTruthy();
});
tap.test('should stop cleanly (tears down shared smartdns client)', async () => {
// If the Rust-backed smartdns bridge wasn't destroyed, this test process
// would hang at exit instead of completing.