Commit 87cd15b3 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2353] Restore time.time() and time.sleep() during tearDown()

parent 3c17e958
...@@ -1231,6 +1231,16 @@ class TestBossComponents(unittest.TestCase): ...@@ -1231,6 +1231,16 @@ class TestBossComponents(unittest.TestCase):
'process': 'cat' 'process': 'cat'
} }
} }
self._tmp_time = None
self._tmp_sleep = None
def tearDown(self):
if self._tmp_time is not None:
time.time = self._tmp_time
if self._tmp_sleep is not None:
time.sleep = self._tmp_sleep
def __unary_hook(self, param): def __unary_hook(self, param):
""" """
...@@ -1610,8 +1620,8 @@ class TestBossComponents(unittest.TestCase): ...@@ -1610,8 +1620,8 @@ class TestBossComponents(unittest.TestCase):
global tsec global tsec
attempts = 0 attempts = 0
tsec = 0 tsec = 0
tmp_time = time.time self._tmp_time = time.time
tmp_sleep = time.sleep self._tmp_sleep = time.sleep
def _my_time(): def _my_time():
global attempts global attempts
global tsec global tsec
...@@ -1633,8 +1643,7 @@ class TestBossComponents(unittest.TestCase): ...@@ -1633,8 +1643,7 @@ class TestBossComponents(unittest.TestCase):
# to happen inside start_msgq(). # to happen inside start_msgq().
self.assertEqual(attempts, 13) self.assertEqual(attempts, 13)
time.time = tmp_time # time.time() and time.sleep() are restored during tearDown().
time.sleep = tmp_sleep
def test_start_cfgmgr(self): def test_start_cfgmgr(self):
'''Test that b10-cfgmgr is started.''' '''Test that b10-cfgmgr is started.'''
...@@ -1717,7 +1726,7 @@ class TestBossComponents(unittest.TestCase): ...@@ -1717,7 +1726,7 @@ class TestBossComponents(unittest.TestCase):
global attempts global attempts
attempts = 0 attempts = 0
tmp_sleep = time.sleep self._tmp_sleep = time.sleep
def _my_sleep(nsec): def _my_sleep(nsec):
global attempts global attempts
attempts += 1 attempts += 1
...@@ -1736,7 +1745,7 @@ class TestBossComponents(unittest.TestCase): ...@@ -1736,7 +1745,7 @@ class TestBossComponents(unittest.TestCase):
# 2 seconds of attempts every 1 second should result in 2 attempts # 2 seconds of attempts every 1 second should result in 2 attempts
self.assertEqual(attempts, 2) self.assertEqual(attempts, 2)
time.sleep = tmp_sleep # time.sleep() is restored during tearDown().
def test_start_ccsession(self): def test_start_ccsession(self):
'''Test that CC session is started.''' '''Test that CC session is started.'''
......
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