mirror of
https://github.com/janet-lang/janet
synced 2026-10-10 01:31:40 +00:00
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).
This commit is contained in:
+11
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user