Use ephemeral port in tests for statsd

This commit is contained in:
Ryan Mclean 2016-08-02 17:41:32 -04:00
parent af62789a96
commit 1fb1f46bc1
2 changed files with 10 additions and 5 deletions

View file

@ -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 = []

View file

@ -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()