From 1fb1f46bc1a49766596f7cf3a03e4017babc9042 Mon Sep 17 00:00:00 2001 From: Ryan Mclean Date: Tue, 2 Aug 2016 17:41:32 -0400 Subject: [PATCH] Use ephemeral port in tests for statsd --- sprockets/mixins/metrics/testing.py | 2 +- tests.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/sprockets/mixins/metrics/testing.py b/sprockets/mixins/metrics/testing.py index 76d77a0..272d996 100644 --- a/sprockets/mixins/metrics/testing.py +++ b/sprockets/mixins/metrics/testing.py @@ -33,7 +33,7 @@ class FakeStatsdServer(object): def __init__(self, iol): self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) - self.socket.bind(('127.0.0.1', 8125)) + self.socket.bind(('127.0.0.1', 0)) self.sockaddr = self.socket.getsockname() self.datagrams = [] diff --git a/tests.py b/tests.py index 4d74168..7ba58e3 100644 --- a/tests.py +++ b/tests.py @@ -41,13 +41,15 @@ class StatsdMetricCollectionTests(testing.AsyncHTTPTestCase): web.url('/', examples.statsd.SimpleHandler), web.url('/counters/(.*)/([.0-9]*)', CounterBumper), ]) - statsd.install(self.application, **{'namespace': 'testing'}) return self.application def setUp(self): self.application = None super(StatsdMetricCollectionTests, self).setUp() self.statsd = FakeStatsdServer(self.io_loop) + statsd.install(self.application, **{'namespace': 'testing', + 'host': self.statsd.sockaddr[0], + 'port': self.statsd.sockaddr[1]}) def tearDown(self): self.statsd.close() @@ -102,9 +104,6 @@ class StatsdConfigurationTests(testing.AsyncHTTPTestCase): web.url('/', examples.statsd.SimpleHandler), web.url('/counters/(.*)/([.0-9]*)', CounterBumper), ]) - statsd.install(self.application, **{'namespace': 'testing', - 'prepend_metric_type': False, - 'prepend_hostname': False}) return self.application def setUp(self): @@ -112,6 +111,12 @@ class StatsdConfigurationTests(testing.AsyncHTTPTestCase): super(StatsdConfigurationTests, self).setUp() self.statsd = FakeStatsdServer(self.io_loop) + statsd.install(self.application, **{'namespace': 'testing', + 'host': self.statsd.sockaddr[0], + 'port': self.statsd.sockaddr[1], + 'prepend_metric_type': False, + 'prepend_hostname': False}) + def tearDown(self): self.statsd.close() super(StatsdConfigurationTests, self).tearDown()