mirror of
https://github.com/sprockets/sprockets.mixins.metrics.git
synced 2024-11-24 19:29:51 +00:00
Added statsd tests for 100% coverage, upgraded coverage pkg and conf
This commit is contained in:
parent
6176ab654d
commit
dc57f5c5d1
4 changed files with 46 additions and 4 deletions
|
@ -1,3 +1,3 @@
|
|||
-r testing.txt
|
||||
coverage>=3.7,<4.1
|
||||
coverage==4.5.1
|
||||
Sphinx
|
||||
|
|
|
@ -3,3 +3,11 @@ universal = 1
|
|||
[nosetests]
|
||||
cover-package = sprockets.mixins.metrics
|
||||
cover-branches = 1
|
||||
cover-erase = 1
|
||||
cover-html = 1
|
||||
cover-html-dir = build/coverage
|
||||
cover-xml = 1
|
||||
match = ((?:^|[\b_.-])(:?[Tt]est|When|should|[Dd]escribe))
|
||||
verbosity = 2
|
||||
with-coverage = 1
|
||||
with-xunit = 1
|
||||
|
|
|
@ -120,6 +120,7 @@ class StatsDCollector(object):
|
|||
self._address = (self._host, self._port)
|
||||
self._namespace = namespace
|
||||
self._prepend_metric_type = prepend_metric_type
|
||||
self._tcp_reconnect_sleep = 5
|
||||
|
||||
if protocol == 'tcp':
|
||||
self._tcp = True
|
||||
|
@ -145,10 +146,9 @@ class StatsDCollector(object):
|
|||
@gen.engine
|
||||
def _tcp_on_closed(self):
|
||||
"""Invoked when the socket is closed."""
|
||||
sleep = 5
|
||||
LOGGER.warning('Not connected to statsd, connecting in %s seconds',
|
||||
sleep)
|
||||
yield gen.sleep(sleep)
|
||||
self._tcp_reconnect_sleep)
|
||||
yield gen.sleep(self._tcp_reconnect_sleep)
|
||||
self._sock = self._tcp_socket()
|
||||
|
||||
def _tcp_on_connected(self):
|
||||
|
|
34
tests.py
34
tests.py
|
@ -44,6 +44,22 @@ def assert_between(low, value, high):
|
|||
value, low, high))
|
||||
|
||||
|
||||
class MisconfiguredStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
||||
|
||||
def get_app(self):
|
||||
self.application = web.Application([
|
||||
web.url('/', examples.statsd.SimpleHandler),
|
||||
web.url('/counters/(.*)/([.0-9]*)', CounterBumper),
|
||||
web.url('/status_code', DefaultStatusCode),
|
||||
])
|
||||
|
||||
def test_bad_protocol_raises_ValueError(self):
|
||||
with self.assertRaises(ValueError):
|
||||
statsd.StatsDCollector(host='127.0.0.1',
|
||||
port=8125,
|
||||
protocol='bad_protocol')
|
||||
|
||||
|
||||
class TCPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
||||
|
||||
def get_app(self):
|
||||
|
@ -67,6 +83,24 @@ class TCPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
|
|||
'protocol': 'tcp',
|
||||
'prepend_metric_type': True})
|
||||
|
||||
def test_tcp_reconnect_on_stream_close(self):
|
||||
path_sleep = 'tornado.gen.sleep'
|
||||
path_statsd = self.application.statsd
|
||||
with mock.patch(path_sleep) as gen_sleep, \
|
||||
patch.object(path_statsd, '_tcp_socket') as mock_tcp_socket:
|
||||
f = web.Future()
|
||||
f.set_result(None)
|
||||
gen_sleep.return_value = f
|
||||
|
||||
self.application.statsd._tcp_on_closed()
|
||||
mock_tcp_socket.assert_called_once_with()
|
||||
|
||||
@patch.object(iostream.IOStream, 'write')
|
||||
def test_write_not_executed_when_connection_is_closed(self, mock_write):
|
||||
self.application.statsd._sock.close()
|
||||
self.application.statsd.send('foo', 500, 'c')
|
||||
mock_write.assert_not_called()
|
||||
|
||||
@patch.object(iostream.IOStream, 'write')
|
||||
def test_expected_counters_data_written(self, mock_sock):
|
||||
path = ('foo', 'bar')
|
||||
|
|
Loading…
Reference in a new issue