def test_timeout_execute(): timeout = 3 # TODO: the timeout should be smaller but as a workaround for Pypy slowness/overhead we set it to 3 sec func = execute.python(timeout=timeout)(sleep_and_return) # Normal case result = func(0.25) assert result == 0.25 # Timeout case t = time.time() with pytest.raises(ExecutionTimeoutError) as e: func(10) assert (time.time() - t) < 10.0 assert 'ExecutionTimeoutError after {} seconds'.format(timeout) in str(e.value)
def test_timeout_execute(): timeout = 3 # TODO: the timeout should be smaller but as a workaround for Pypy slowness/overhead we set it to 3 sec func = execute.python(timeout=timeout)(sleep_and_return) # Normal case result = func(0.25) assert result == 0.25 # Timeout case t = time.time() with pytest.raises(ExecutionTimeoutError) as e: func(10) assert (time.time() - t) < 10.0 assert 'ExecutionTimeoutError after {} seconds'.format(timeout) in str(e.value)
def test_execute_kill_children(): pid = execute.python(kill_children=True)(create_sleeper_subprocess)() with pytest.raises(psutil.NoSuchProcess): psutil.Process(pid)
def test_execute_dont_kill_children(): pid = execute.python()(create_sleeper_subprocess)() subprocess = psutil.Process(pid) assert subprocess.status() == 'sleeping' subprocess.terminate() # cleanup
def test_execute_kill_children(): pid = execute.python(kill_children=True)(create_sleeper_subprocess)() with pytest.raises(psutil.NoSuchProcess): psutil.Process(pid)
def test_execute_dont_kill_children(): pid = execute.python()(create_sleeper_subprocess)() subprocess = psutil.Process(pid) assert subprocess.status() == 'sleeping' subprocess.terminate() # cleanup