Skip to content

Commit 8314969

Browse files
committed
Switch local HTTP server to not do rDNS lookup on startup
1 parent 0508f78 commit 8314969

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

tests/fixtures_http.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,33 @@
3232
import contextlib
3333
import functools
3434
import http.server
35+
import socketserver
3536
import threading
3637
from pathlib import Path
3738
from typing import Callable, Generator
3839

3940
import pytest
4041

4142

43+
class NoNameLookupHTTPServer(http.server.HTTPServer):
44+
"""HTTPServer subclass that doesn't do rDNS lookup when setting server name.
45+
46+
We use this class because the macOS GitHub runners time out when attempting
47+
the rDNS lookup.
48+
49+
"""
50+
51+
def server_bind(self):
52+
"""Override server_bind to store the server name."""
53+
socketserver.TCPServer.server_bind(self)
54+
host, port = self.server_address[:2]
55+
self.server_name = host # Override
56+
self.server_port = port
57+
58+
4259
@contextlib.contextmanager
4360
def _baseurl_for_served_directory(
44-
directory: Path | str, host: str = "localhost"
61+
directory: Path | str, host: str = "127.0.0.1"
4562
) -> Generator[str, None, None]:
4663
"""Spin up HTTP server on a directory and yield the server base URL."""
4764
directory = Path(directory).resolve()
@@ -52,7 +69,7 @@ def _baseurl_for_served_directory(
5269
)
5370

5471
# Bind to port 0 so the OS chooses a free ephemeral port
55-
httpd = http.server.HTTPServer((host, 0), handler_cls)
72+
httpd = NoNameLookupHTTPServer((host, 0), handler_cls)
5673
port = httpd.server_address[1]
5774
base_url = f"http://{host}:{port}"
5875

0 commit comments

Comments
 (0)