Commit f0be8d52 authored by Jérome Perrin's avatar Jérome Perrin

tests: update monitor tests for python3

timing seems to be slightly different (I did not investigate much)
parent d4abf3ff
...@@ -68,11 +68,14 @@ class TestMonitorMemory(unittest.TestCase): ...@@ -68,11 +68,14 @@ class TestMonitorMemory(unittest.TestCase):
def testMonitorWithLittleMemoryLimit(self): def testMonitorWithLittleMemoryLimit(self):
"""Test the monitor with limit of 10Mb. In This case the openoffice will be """Test the monitor with limit of 10Mb. In This case the openoffice will be
stopped""" stopped after some time"""
try: try:
self.monitor = MonitorMemory(openoffice, 2, 10) self.monitor = MonitorMemory(openoffice, 1, 10)
self.monitor.start() self.monitor.start()
sleep(self.interval) for _ in range(30):
sleep(1)
if not openoffice.status():
break
self.assertEqual(openoffice.status(), False) self.assertEqual(openoffice.status(), False)
finally: finally:
self.monitor.terminate() self.monitor.terminate()
...@@ -99,11 +102,9 @@ class TestMonitorMemory(unittest.TestCase): ...@@ -99,11 +102,9 @@ class TestMonitorMemory(unittest.TestCase):
"""Test memory usage""" """Test memory usage"""
self.monitor = MonitorMemory(openoffice, 2, 400) self.monitor = MonitorMemory(openoffice, 2, 400)
openoffice.stop() openoffice.stop()
memory_usage_int = self.monitor.get_memory_usage() memory_usage = self.monitor.get_memory_usage()
self.assertEqual(memory_usage_int, 0) self.assertEqual(memory_usage, 0)
if not openoffice.status(): if not openoffice.status():
openoffice.start() openoffice.start()
memory_usage_int = self.monitor.get_memory_usage() memory_usage = self.monitor.get_memory_usage()
self.assertIsInstance(memory_usage_int, int) self.assertIsInstance(memory_usage, int)
...@@ -61,13 +61,15 @@ class TestMonitorTimeout(unittest.TestCase): ...@@ -61,13 +61,15 @@ class TestMonitorTimeout(unittest.TestCase):
try: try:
monitor_timeout = self._createMonitor(1) monitor_timeout = self._createMonitor(1)
monitor_timeout.start() monitor_timeout.start()
sleep(2) sleep(5)
self.assertEqual(openoffice.status(), False) self.assertEqual(openoffice.status(), False)
openoffice.restart() openoffice.restart()
self.assertTrue(openoffice.status()) self.assertTrue(openoffice.status())
finally: finally:
monitor_timeout.terminate() try:
openoffice.release() monitor_timeout.terminate()
finally:
openoffice.release()
def testStopOpenOfficeTwice(self): def testStopOpenOfficeTwice(self):
"""Test the cases that is necessary start the monitors twice""" """Test the cases that is necessary start the monitors twice"""
...@@ -75,20 +77,22 @@ class TestMonitorTimeout(unittest.TestCase): ...@@ -75,20 +77,22 @@ class TestMonitorTimeout(unittest.TestCase):
try: try:
monitor_timeout = self._createMonitor(1) monitor_timeout = self._createMonitor(1)
monitor_timeout.start() monitor_timeout.start()
sleep(2) sleep(5)
self.assertEqual(openoffice.status(), False) self.assertEqual(openoffice.status(), False)
monitor_timeout.terminate() monitor_timeout.terminate()
openoffice.restart() openoffice.restart()
self.assertTrue(openoffice.status()) self.assertTrue(openoffice.status())
monitor_timeout = self._createMonitor(1) monitor_timeout = self._createMonitor(1)
monitor_timeout.start() monitor_timeout.start()
sleep(2) sleep(5)
self.assertEqual(openoffice.status(), False) self.assertEqual(openoffice.status(), False)
monitor_timeout.terminate() monitor_timeout.terminate()
sleep(1) sleep(1)
self.assertEqual(monitor_timeout.is_alive(), False) self.assertEqual(monitor_timeout.is_alive(), False)
finally: finally:
monitor_timeout.terminate() try:
openoffice.release() monitor_timeout.terminate()
finally:
openoffice.release()
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