Commit 44ac42cc5 for clamav.net
commit 44ac42cc5dc002159c1d650843f828b3cb7dfda5
Author: Val S. <valsnyde@cisco.com>
Date: Fri Jul 10 10:04:39 2026 -0400
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.
diff --git a/unit_tests/freshclam_test.py b/unit_tests/freshclam_test.py
index dccb3845e..93b152171 100644
--- a/unit_tests/freshclam_test.py
+++ b/unit_tests/freshclam_test.py
@@ -15,6 +15,7 @@ import unittest
from functools import partial
from http.server import HTTPServer, BaseHTTPRequestHandler
+from socketserver import TCPServer
import testcase
@@ -25,7 +26,17 @@ MOCK_MIRROR_IPV6_HOST = '::1'
MOCK_MIRROR_START_TIMEOUT = 10
-class IPv6HTTPServer(HTTPServer):
+class MockMirrorHTTPServer(HTTPServer):
+ '''
+ HTTPServer variant that avoids reverse DNS during local test server startup.
+ '''
+ def server_bind(self):
+ TCPServer.server_bind(self)
+ self.server_name = self.server_address[0]
+ self.server_port = self.server_address[1]
+
+
+class IPv6HTTPServer(MockMirrorHTTPServer):
address_family = socket.AF_INET6
@@ -861,7 +872,7 @@ def create_mock_database_mirror_server(handler, port):
last_error = None
for server_class, host in (
- (HTTPServer, MOCK_MIRROR_IPV4_HOST),
+ (MockMirrorHTTPServer, MOCK_MIRROR_IPV4_HOST),
(IPv6HTTPServer, MOCK_MIRROR_IPV6_HOST),
):
try: