Skip to content

Commit f641277

Browse files
committed
Add test for stats packets across boundaries.
1 parent 10fc811 commit f641277

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/collectors/memcached/test/testmemcached.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from test import CollectorTestCase
66
from test import get_collector_config
77
from test import unittest
8+
from mock import MagicMock
89
from mock import Mock
910
from mock import patch
1011

@@ -27,6 +28,15 @@ def setUp(self):
2728
def test_import(self):
2829
self.assertTrue(MemcachedCollector)
2930

31+
@patch('socket.socket')
32+
def test_get_raw_stats_works_across_packet_boundaries(self, socket_mock):
33+
socket_instance = MagicMock()
34+
socket_mock.return_value = socket_instance
35+
stats_packets = ['stat foo 1\r\n', 'END\r\n']
36+
socket_instance.recv.side_effect = stats_packets
37+
stats = self.collector.get_raw_stats('', None)
38+
self.assertEqual(stats, ''.join(stats_packets))
39+
3040
@patch.object(Collector, 'publish')
3141
def test_should_work_with_real_data(self, publish_mock):
3242
patch_raw_stats = patch.object(

0 commit comments

Comments
 (0)