diff options
Diffstat (limited to 'test/bun.js/resolve-dns.test.ts')
-rw-r--r-- | test/bun.js/resolve-dns.test.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/bun.js/resolve-dns.test.ts b/test/bun.js/resolve-dns.test.ts new file mode 100644 index 000000000..f0db49b20 --- /dev/null +++ b/test/bun.js/resolve-dns.test.ts @@ -0,0 +1,54 @@ +import { dns } from "bun"; +import { describe, expect, it, test } from "bun:test"; +import { withoutAggressiveGC } from "gc"; + +describe("dns.lookup", () => { + const backends = [ + process.platform === "darwin" ? "system" : undefined, + "libc", + "c-ares", + ].filter(Boolean); + for (let backend of backends) { + it(backend + " parallell x 10", async () => { + const promises = []; + for (let i = 0; i < 10; i++) { + promises.push(dns.lookup("localhost", { backend })); + } + const results = (await Promise.all(promises)).flat(); + withoutAggressiveGC(() => { + for (let { family, address } of results) { + if (family === 4) { + expect(address).toBe("127.0.0.1"); + } else if (family === 6) { + expect(address).toBe("::1"); + } else { + throw new Error("Unknown family"); + } + } + }); + }); + + it(backend + " remote", async () => { + const [first, second] = await dns.lookup("google.com", { backend }); + console.log(first, second); + }); + it(backend + " local", async () => { + const [first, second] = await dns.lookup("localhost", { backend }); + console.log(first, second); + }); + + it( + backend + + " failing domain throws an error without taking a very long time", + async () => { + try { + await dns.lookup("yololololololo1234567.com", { backend }); + throw 42; + } catch (e) { + expect(typeof e).not.toBe("number"); + expect(e.code).toBe("DNS_ENOTFOUND"); + } + }, + ); + } +}); |