Commit 92b8b8d0 authored by Charles Ferguson's avatar Charles Ferguson
Browse files

Fix for thread control tests on linux.

The 'netstat -i -c' command, when run as an unprivileged user, appears
to output nothing. This makes our tests fail because we rely on it
outputing something every second.

Change to using ping.
parent 2d52ba98
...@@ -155,9 +155,10 @@ class StreamedInput(object): ...@@ -155,9 +155,10 @@ class StreamedInput(object):
else: else:
stopped = 'running' stopped = 'running'
return "StreamedInput(command=%r, shell=%r, buffer_size=%s; " \ return "%s(command=%r, shell=%r, buffer_size=%s; " \
"started=%s, stopped=%s, data_function=%s%s)" % \ "started=%s, stopped=%s, data_function=%s%s)" % \
(self.command, self.shell, self.buffer_size, (self.__class__.__name__,
self.command, self.shell, self.buffer_size,
self.proc is not None, stopped, datafunc, extra) self.proc is not None, stopped, datafunc, extra)
def _set_nonblocking(self): def _set_nonblocking(self):
......
...@@ -514,9 +514,9 @@ class TestThreaded90ThreadControl(BaseThreadedInput): ...@@ -514,9 +514,9 @@ class TestThreaded90ThreadControl(BaseThreadedInput):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(TestThreaded90ThreadControl, self).__init__(*args, **kwargs) super(TestThreaded90ThreadControl, self).__init__(*args, **kwargs)
if sys.platform == 'darwin': if sys.platform == 'darwin':
self.netstat = ['netstat', '-i', '-w1'] self.cmd = ['netstat', '-i', '-w1']
elif sys.platform.startswith('linux'): elif sys.platform.startswith('linux'):
self.netstat = ['netstat', '-i', '-c'] self.cmd = ['ping', '-c', '4', '127.0.0.1']
else: else:
raise NotImplementedError raise NotImplementedError
...@@ -527,7 +527,7 @@ class TestThreaded90ThreadControl(BaseThreadedInput): ...@@ -527,7 +527,7 @@ class TestThreaded90ThreadControl(BaseThreadedInput):
super(TestThreaded90ThreadControl, self).tearDown() super(TestThreaded90ThreadControl, self).tearDown()
def test_001_start_and_stop_long_process(self): def test_001_start_and_stop_long_process(self):
self.si = streamedinput.StreamedInput(self.netstat) self.si = streamedinput.StreamedInput(self.cmd)
self.si.start() self.si.start()
time.sleep(0.1) time.sleep(0.1)
initial_datalen = len(self.si) initial_datalen = len(self.si)
...@@ -553,7 +553,7 @@ class TestThreaded90ThreadControl(BaseThreadedInput): ...@@ -553,7 +553,7 @@ class TestThreaded90ThreadControl(BaseThreadedInput):
self.assertTrue(self.si.eof(), "We should now be at the end of the list, and the process should be gone") self.assertTrue(self.si.eof(), "We should now be at the end of the list, and the process should be gone")
def test_002_context_handler_stops(self): def test_002_context_handler_stops(self):
with streamedinput.ThreadedStreamedInput(self.netstat) as self.si: with streamedinput.ThreadedStreamedInput(self.cmd) as self.si:
test_process = psutil.Process(self.si.proc.pid) test_process = psutil.Process(self.si.proc.pid)
self.assertTrue(self.si.is_running(), "Process should be running") self.assertTrue(self.si.is_running(), "Process should be running")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment