From ba17c47e069882aefedc45babc6119dbfaf00822 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Tue, 8 Sep 2026 09:23:21 +0000 Subject: [PATCH] Don't hardcode 127.0.0.1 in tests How about we resolve through the special host name "localhost." instead of assuming that the loopback interface is bound to 127.0.0.1 (which might not be the case, especially in FreeBSD jails)? See RFC6761 for how "localhost." is treated, especially: Name resolution APIs and libraries SHOULD recognize localhost names as special and SHOULD always return the IP loopback address for address queries and negative responses for all other query types. Name resolution APIs SHOULD NOT send queries for localhost names to their configured caching DNS server(s). --- test/suite-ev.janet | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/suite-ev.janet b/test/suite-ev.janet index 30c2e154..237ef0cc 100644 --- a/test/suite-ev.janet +++ b/test/suite-ev.janet @@ -23,8 +23,18 @@ (setdyn *lint-warn* :none) +(defn decide-test-host [port] + (if-let [host (os/getenv "JANET_TEST_HOST")] + host + (try + (let [s (net/listen "localhost." port) + [host _] (net/localname s)] + (net/close s) + host) + ([] "127.0.0.1")))) + (def test-port (os/getenv "JANET_TEST_PORT" "8761")) -(def test-host (os/getenv "JANET_TEST_HOST" "127.0.0.1")) +(def test-host (decide-test-host test-port)) # Subprocess # 5e1a8c86f