Skip to content

Commit e6b7361

Browse files
matthewoliverbenformosacsmart
committed
FakeStatsdClient: Stop issuing DNS calls for host.
Running unittests on my home server, even though is a beast, would be painfully slow. Running them on my laptop ran much faster. I tried everything and couldn't figure it out. Chris, co-author, dug in and after we ran out of options he fired up his packet capture and realised most tests were issuing DNS queries for `host.`. On my home server, it runs ipv6 dual stack, so these calls would need to timeout before a test can continue. On finding this `host.` Ben, another co-author, dug into the code and found the only reference we have to `host` is in FakeStatsdClient. Sure enough as I dug a little further it turns out our FakeStatsdClient used to override a StatsdClient function `_determine_sock_family(self, host, port)` to stop actually creating a real socket. However, at some point the StatsdClient was refactored and that method was renamed and changed. Which leads to a DNS lookup every time we create a debug_logger as it brings up the socket. As you can imagine, this happens alot! This patch overrides the new function that handles to socket creation `_set_sock_family_and_target(self, host, port)`. Which eliminates the DNS call all together. Co-Authored-By: Ben Formosa <[email protected]> Co-Authored-By: Chris Smart <[email protected]> Change-Id: Ie393075f79447627714692e3f01bb53e967a71e8
1 parent 1d5e65c commit e6b7361

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

test/debug_logger.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def wrapper(*args, **kwargs):
6565
return func(*args, **kwargs)
6666
return wrapper
6767

68-
def _determine_sock_family(self, host, port):
69-
return None, None
68+
def _set_sock_family_and_target(self, host, port):
69+
self._target = (host, port)
7070

7171
def _open_socket(self):
7272
return self.recording_socket
@@ -113,6 +113,7 @@ class CaptureLog(object):
113113
Captures log records passed to the ``handle`` method and provides accessor
114114
functions to the captured logs.
115115
"""
116+
116117
def __init__(self):
117118
self.clear()
118119

@@ -280,6 +281,7 @@ class ForwardingLogHandler(logging.NullHandler):
280281
to a given handler function. This can be useful to forward records to a
281282
handler without the handler itself needing to subclass LogHandler.
282283
"""
284+
283285
def __init__(self, handler_fn):
284286
super(ForwardingLogHandler, self).__init__()
285287
self.handler_fn = handler_fn
@@ -293,6 +295,7 @@ class CaptureLogAdapter(utils.LogAdapter, CaptureLog):
293295
A LogAdapter that is capable of capturing logs for inspection via accessor
294296
methods.
295297
"""
298+
296299
def __init__(self, logger, name):
297300
super(CaptureLogAdapter, self).__init__(logger, name)
298301
self.clear()

0 commit comments

Comments
 (0)