Skip to content

Commit

Permalink
increase autoSelectFamilyAttemptTimeout in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Nov 11, 2024
1 parent 1c010b9 commit 8d80d1d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
46 changes: 38 additions & 8 deletions ext/node/polyfills/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ const kBytesWritten = Symbol("kBytesWritten");
const DEFAULT_IPV4_ADDR = "0.0.0.0";
const DEFAULT_IPV6_ADDR = "::";

// TODO(kt3k): Implement `setDefaultAutoSelectFamily` API to allow users
// to set this value.
const autoSelectFamilyDefault = true;
let autoSelectFamilyDefault = true;
let autoSelectFamilyAttemptTimeoutDefault = 250;

type Handle = TCP | Pipe;

Expand Down Expand Up @@ -876,7 +875,7 @@ function _lookupAndConnect(
autoSelectFamilyAttemptTimeout = 10;
}
} else {
autoSelectFamilyAttemptTimeout = 250;
autoSelectFamilyAttemptTimeout = autoSelectFamilyAttemptTimeoutDefault;
}

// If host is an IP, skip performing a lookup
Expand Down Expand Up @@ -2025,6 +2024,33 @@ export function connect(...args: unknown[]) {

export const createConnection = connect;

/** https://docs.deno.com/api/node/net/#namespace_getdefaultautoselectfamily */
export function getDefaultAutoSelectFamily() {
return autoSelectFamilyDefault;
}

/** https://docs.deno.com/api/node/net/#namespace_setdefaultautoselectfamily */
export function setDefaultAutoSelectFamily(value: boolean) {
validateBoolean(value, "value");
autoSelectFamilyDefault = value;
}

/** https://docs.deno.com/api/node/net/#namespace_getdefaultautoselectfamilyattempttimeout */
export function getDefaultAutoSelectFamilyAttemptTimeout() {
return autoSelectFamilyAttemptTimeoutDefault;
}

/** https://docs.deno.com/api/node/net/#namespace_setdefaultautoselectfamilyattempttimeout */
export function setDefaultAutoSelectFamilyAttemptTimeout(value: number) {
validateInt32(value, "value", 1);

if (value < 10) {
value = 10;
}

autoSelectFamilyAttemptTimeoutDefault = value;
}

export interface ListenOptions extends Abortable {
fd?: number;
port?: number | undefined;
Expand Down Expand Up @@ -2910,15 +2936,19 @@ export { BlockList, isIP, isIPv4, isIPv6, SocketAddress };
export default {
_createServerHandle,
_normalizeArgs,
isIP,
isIPv4,
isIPv6,
BlockList,
SocketAddress,
connect,
createConnection,
createServer,
getDefaultAutoSelectFamily,
getDefaultAutoSelectFamilyAttemptTimeout,
isIP,
isIPv4,
isIPv6,
Server,
setDefaultAutoSelectFamily,
setDefaultAutoSelectFamilyAttemptTimeout,
Socket,
SocketAddress,
Stream,
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function createDnsServer(ipv6Addrs, ipv4Addrs, cb) {
// Create a DNS server which replies with a AAAA and a A record for the same host
const socket = dgram.createSocket('udp4');

// Note(kt3k): Deno seems sending more than on message to the DNS server.
// Note(kt3k): Deno seems sending more than one message to the DNS server.
socket.on('message', common.mustCallAtLeast((msg, { address, port }) => {
const parsed = parseDNSPacket(msg);
const domain = parsed.questions[0].domain;
Expand Down
9 changes: 6 additions & 3 deletions tests/unit_node/http2_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import * as net from "node:net";
import { assert, assertEquals } from "@std/assert";
import { curlRequest } from "../unit/test_util.ts";

// Increase the timeout for the auto select family to avoid flakiness
net.setDefaultAutoSelectFamilyAttemptTimeout(
net.getDefaultAutoSelectFamilyAttemptTimeout() * 30,
);

for (const url of ["http://localhost:4246", "https://localhost:4247"]) {
Deno.test(`[node/http2 client] ${url}`, {
ignore: Deno.build.os === "windows",
Expand Down Expand Up @@ -114,9 +119,7 @@ Deno.test(`[node/http2 client createConnection]`, {
assertEquals(receivedData, "hello world\n");
});

// TODO(kt3k): Enable this test
const TEST_NAME = "[node/http2 client GET https://www.example.com]";
Deno.test(TEST_NAME, { ignore: true }, async () => {
Deno.test("[node/http2 client GET https://www.example.com]", async () => {
const clientSession = http2.connect("https://www.example.com");
const req = clientSession.request({
":method": "GET",
Expand Down

0 comments on commit 8d80d1d

Please sign in to comment.