Kill mutate-changes' surviving mutants: test a deleted file, a mutmut results that cannot start, an interrupt's speed, and a process group already gone
This commit is contained in:
@@ -9,6 +9,7 @@ import textwrap
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
@@ -211,7 +212,28 @@ class ToolProcess(unittest.TestCase):
|
||||
def test_a_scratch_folder_it_cannot_make_is_a_failure(self):
|
||||
self.assertRegex(scratch_folder("/nonexistent/top").reason, "^could not make a scratch folder in /nonexistent/top: ")
|
||||
|
||||
def test_an_interrupted_run_ends_each_process_the_tool_started(self):
|
||||
def test_an_interrupted_run_ends_at_once_with_each_process_the_tool_started(self):
|
||||
sleeper, took = self.interrupted()
|
||||
self.assertLess(took, 30)
|
||||
for _ in range(200):
|
||||
if ended(sleeper):
|
||||
break
|
||||
time.sleep(0.05)
|
||||
else:
|
||||
self.fail(f"sleep {sleeper}, which the tool started, still runs")
|
||||
|
||||
def test_an_interrupt_ends_the_run_where_the_tool_s_processes_end_first(self):
|
||||
killpg = os.killpg
|
||||
|
||||
def then_gone(group: int, number: int) -> None:
|
||||
killpg(group, number)
|
||||
raise ProcessLookupError
|
||||
|
||||
with unittest.mock.patch("os.killpg", then_gone):
|
||||
self.interrupted()
|
||||
|
||||
def interrupted(self) -> tuple[int, float]:
|
||||
"""Interrupt run_tool once its tool has started a sleep of 60 s: the sleep's pid, and how long run_tool took."""
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
started = pathlib.Path(temp, "sleep.pid")
|
||||
|
||||
@@ -221,15 +243,10 @@ class ToolProcess(unittest.TestCase):
|
||||
os.kill(os.getpid(), signal.SIGINT)
|
||||
|
||||
threading.Thread(target=interrupt, daemon=True).start()
|
||||
began = time.monotonic()
|
||||
with self.assertRaises(KeyboardInterrupt):
|
||||
run_tool(["true"], temp, f"sleep 60 & echo $! > {started}; wait;")
|
||||
sleeper = int(started.read_text())
|
||||
for _ in range(200):
|
||||
if ended(sleeper):
|
||||
break
|
||||
time.sleep(0.05)
|
||||
else:
|
||||
self.fail(f"sleep {sleeper}, which the tool started, still runs")
|
||||
return int(started.read_text()), time.monotonic() - began
|
||||
|
||||
|
||||
def ended(pid: int) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user