mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 03:48:56 +00:00
* Boilerplate for DNS stuff * Add c-ares * lookup * make * Implement dns.lookup * Create c-ares * wip * normalize * repro * Revert "repro" This reverts commit 8b93e0c295b335b8882a9601da47720348549beb. * Implement macOS `getaddrinfo_async_start` * embiggen * Update string_immutable.zig * Update Makefile * alright * Update .gitignore * Add types * more ccache * Update Dockerfile * Update Dockerfile * Update Dockerfile * Update bun.d.ts Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
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");
|
|
}
|
|
},
|
|
);
|
|
}
|
|
});
|