def test_safe_shell_exec_interrupts_on_event(self): # interrupt execute in one second interrupt = threading.Event() interrupt_delay = 1.0 delay(lambda: interrupt.set(), interrupt_delay) sleep = interrupt_delay + safe_shell_exec.GRACEFUL_TERMINATION_TIME_S + 2.0 start = time.time() self.do_test_safe_shell_exec('sleep {}'.format(sleep), 143, '', None, interrupt) duration = time.time() - start self.assertGreaterEqual(duration, interrupt_delay) self.assertLess(duration, sleep - 1.0, 'sleep should not finish')
def test_safe_shell_exec_interrupts_on_event(self): # interrupt execute in one second interrupt = threading.Event() delay(lambda: interrupt.set(), 1.0) sleep = 10 start = time.time() self._do_test_safe_shell_exec('sleep {}'.format(sleep), 143, '', 'Terminated\n', interrupt) duration = time.time() - start self.assertGreaterEqual(duration, 1.0) self.assertLess(duration, 2.0 + safe_shell_exec.GRACEFUL_TERMINATION_TIME_S, 'sleep should not finish') self.assertGreater( sleep, 2.0 + safe_shell_exec.GRACEFUL_TERMINATION_TIME_S, 'sleep should allow for GRACEFUL_TERMINATION_TIME_S')