fix(ipintelligence): apply configured timeout to MMDB downloads and expose IP intelligence timeout option
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user