From 646651260aca01358165bb93a054ac5ace65fc20 Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Mon, 15 Oct 2012 11:32:26 -0700 Subject: [PATCH] Make StatsD tests less flaky. There have been a bunch of Jenkins failures lately where the StatsD tests fail because they can't bind to their desired port. There's nothing special about the particular port they're using, so now we let the kernel pick an available one for us. This also lets us get rid of a sleep() in the test that looked like an attempt to alleviate EADDRINUSE errors, so now in the happy case, the tests are a few fractions of a second faster. Change-Id: Idee11349254107a59643539b1566f3588eee7ef4 --- test/unit/common/test_utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 8274fe3c89..6eaeea0f04 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -984,9 +984,9 @@ class TestStatsdLogging(unittest.TestCase): class TestStatsdLoggingDelegation(unittest.TestCase): def setUp(self): - self.port = 9177 self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.sock.bind(('localhost', self.port)) + self.sock.bind(('localhost', 0)) + self.port = self.sock.getsockname()[1] self.queue = Queue() self.reader_thread = Thread(target=self.statsd_reader) self.reader_thread.setDaemon(1) @@ -1004,7 +1004,6 @@ class TestStatsdLoggingDelegation(unittest.TestCase): self.reader_thread.join(timeout=4) self.sock.close() del self.logger - time.sleep(0.15) # avoid occasional "Address already in use"? def statsd_reader(self): while True: