mirror of
https://github.com/sprockets/sprockets.mixins.metrics.git
synced 2024-11-22 03:00:25 +00:00
set protocal with str 'protocol' as per code review
This commit is contained in:
parent
ce352daf0e
commit
b5d1cae249
2 changed files with 10 additions and 8 deletions
|
@ -12,7 +12,7 @@ class FakeStatsdServer(tcpserver.TCPServer):
|
|||
Implements something resembling a statsd server.
|
||||
|
||||
:param tornado.ioloop.IOLoop iol: the loop to attach to
|
||||
:param bool tcp: whether the server implements TCP or UDP
|
||||
:param str protocol: The StatsD protocol. May be either ``udp`` or ``tcp``.
|
||||
|
||||
Create an instance of this class in your asynchronous test case
|
||||
attached to the IOLoop and configure your application to send
|
||||
|
@ -32,13 +32,15 @@ class FakeStatsdServer(tcpserver.TCPServer):
|
|||
|
||||
PATTERN = br'(?P<path>[^:]*):(?P<value>[^|]*)\|(?P<type>.*)$'
|
||||
|
||||
def __init__(self, iol, tcp=False):
|
||||
def __init__(self, iol, protocol='udp'):
|
||||
self.datagrams = []
|
||||
|
||||
if tcp is False:
|
||||
if protocol == 'tcp':
|
||||
self.tcp_server()
|
||||
elif protocol == 'udp':
|
||||
self.udp_server(iol)
|
||||
else:
|
||||
self.tcp_server()
|
||||
raise ValueError('Invalid protocol: {}'.format(protocol))
|
||||
|
||||
def tcp_server(self):
|
||||
self.event = locks.Event()
|
||||
|
|
8
tests.py
8
tests.py
|
@ -55,7 +55,7 @@ class TCPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
def setUp(self):
|
||||
self.application = None
|
||||
super(TCPStatsdMetricCollectionTests, self).setUp()
|
||||
self.statsd = FakeStatsdServer(self.io_loop, tcp=True)
|
||||
self.statsd = FakeStatsdServer(self.io_loop, protocol='tcp')
|
||||
|
||||
statsd.install(self.application, **{'namespace': 'testing',
|
||||
'host': self.statsd.sockaddr[0],
|
||||
|
@ -121,7 +121,7 @@ class TCPStatsdConfigurationTests(testing.AsyncHTTPTestCase):
|
|||
def setUp(self):
|
||||
self.application = None
|
||||
super(TCPStatsdConfigurationTests, self).setUp()
|
||||
self.statsd = FakeStatsdServer(self.io_loop, tcp=True)
|
||||
self.statsd = FakeStatsdServer(self.io_loop, protocol='tcp')
|
||||
|
||||
statsd.install(self.application, **{'namespace': 'testing',
|
||||
'host': self.statsd.sockaddr[0],
|
||||
|
@ -159,7 +159,7 @@ class UDPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
def setUp(self):
|
||||
self.application = None
|
||||
super(UDPStatsdMetricCollectionTests, self).setUp()
|
||||
self.statsd = FakeStatsdServer(self.io_loop, tcp=False)
|
||||
self.statsd = FakeStatsdServer(self.io_loop, protocol='udp')
|
||||
|
||||
statsd.install(self.application, **{'namespace': 'testing',
|
||||
'host': self.statsd.sockaddr[0],
|
||||
|
@ -229,7 +229,7 @@ class UDPStatsdConfigurationTests(testing.AsyncHTTPTestCase):
|
|||
def setUp(self):
|
||||
self.application = None
|
||||
super(UDPStatsdConfigurationTests, self).setUp()
|
||||
self.statsd = FakeStatsdServer(self.io_loop, tcp=False)
|
||||
self.statsd = FakeStatsdServer(self.io_loop, protocol='udp')
|
||||
|
||||
statsd.install(self.application, **{'namespace': 'testing',
|
||||
'host': self.statsd.sockaddr[0],
|
||||
|
|
Loading…
Reference in a new issue