Skip to content

Commit 44ac42c

Browse files
authored
Tests: Avoid DNS lookup in freshclam mock mirror (#1763)
The freshclam tests start a local HTTP server in a child process and wait for a readiness message before running freshclam. On newer macOS runners, the standard HTTPServer startup can stall while resolving the bound loopback address to a fully-qualified name, so the child process never reports readiness and the tests time out before freshclam is exercised. Use a test-only HTTPServer subclass that binds through TCPServer.server_bind() and records the bound address directly. The mock mirror does not need reverse DNS, and avoiding it keeps startup dependent only on the local socket bind.
1 parent 6c1d28b commit 44ac42c

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

unit_tests/freshclam_test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from functools import partial
1616

1717
from http.server import HTTPServer, BaseHTTPRequestHandler
18+
from socketserver import TCPServer
1819

1920
import testcase
2021

@@ -25,7 +26,17 @@
2526
MOCK_MIRROR_START_TIMEOUT = 10
2627

2728

28-
class IPv6HTTPServer(HTTPServer):
29+
class MockMirrorHTTPServer(HTTPServer):
30+
'''
31+
HTTPServer variant that avoids reverse DNS during local test server startup.
32+
'''
33+
def server_bind(self):
34+
TCPServer.server_bind(self)
35+
self.server_name = self.server_address[0]
36+
self.server_port = self.server_address[1]
37+
38+
39+
class IPv6HTTPServer(MockMirrorHTTPServer):
2940
address_family = socket.AF_INET6
3041

3142

@@ -861,7 +872,7 @@ def create_mock_database_mirror_server(handler, port):
861872
last_error = None
862873

863874
for server_class, host in (
864-
(HTTPServer, MOCK_MIRROR_IPV4_HOST),
875+
(MockMirrorHTTPServer, MOCK_MIRROR_IPV4_HOST),
865876
(IPv6HTTPServer, MOCK_MIRROR_IPV6_HOST),
866877
):
867878
try:

0 commit comments

Comments
 (0)