Wrap time.sleep into wrapper function

In case if it was interrupted by SIGCHLD but scheduled awake time is not
reached it will continue sleeping. For all other signals behaviuor is
not changed.
This commit is contained in:
Alexander Kukushkin
2015-05-28 15:47:51 +02:00
parent cd5e589620
commit aa486194ae
6 changed files with 130 additions and 59 deletions
+44
View File
@@ -0,0 +1,44 @@
import os
import time
import unittest
from helpers.utils import sigchld_handler, sigterm_handler, sleep
def nop(*args, **kwargs):
pass
def os_waitpid(a, b):
return (0, 0)
def time_sleep(_):
sigchld_handler(None, None)
class TestUtils(unittest.TestCase):
def __init__(self, method_name='runTest'):
self.setUp = self.set_up
self.tearDown = self.tear_down
super(TestUtils, self).__init__(method_name)
def set_up(self):
self.time_sleep = time.sleep
time.sleep = nop
def tear_down(self):
time.sleep = self.time_sleep
def test_sigterm_handler(self):
self.assertRaises(SystemExit, sigterm_handler, None, None)
def test_sigchld_handler(self):
sigchld_handler(None, None)
os.waitpid = os_waitpid
sigchld_handler(None, None)
def test_sleep(self):
time.sleep = time_sleep
sleep(0.01)