Skip to content

Commit e4b0f12

Browse files
committed
Add test that reproduces the issue
1 parent 36d0104 commit e4b0f12

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tests/test_concurrency.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ class SigtermTest(CoverageTest):
705705
"""Tests of our handling of SIGTERM."""
706706

707707
@pytest.mark.parametrize("sigterm", [False, True])
708-
def test_sigterm_saves_data(self, sigterm: bool) -> None:
708+
def test_sigterm_multiprocessing_saves_data(self, sigterm: bool) -> None:
709709
# A terminated process should save its coverage data.
710710
self.make_file("clobbered.py", """\
711711
import multiprocessing
@@ -751,6 +751,28 @@ def subproc(x):
751751
expected = "clobbered.py 17 5 71% 5-10"
752752
assert self.squeezed_lines(out)[2] == expected
753753

754+
def test_sigterm_threading_saves_data(self) -> None:
755+
# A terminated process should save its coverage data.
756+
self.make_file("handler.py", """\
757+
import os, signal
758+
759+
print("START", flush=True)
760+
print("SIGTERM", flush=True)
761+
os.kill(os.getpid(), signal.SIGTERM)
762+
print("NOT HERE", flush=True)
763+
""")
764+
self.make_file(".coveragerc", """\
765+
[run]
766+
# The default concurrency option.
767+
concurrency = thread
768+
sigterm = true
769+
""")
770+
out = self.run_command("coverage run handler.py")
771+
assert out == "START\nSIGTERM\nTerminated\n"
772+
out = self.run_command("coverage report -m")
773+
expected = "handler.py 5 1 80% 6"
774+
assert self.squeezed_lines(out)[2] == expected
775+
754776
def test_sigterm_still_runs(self) -> None:
755777
# A terminated process still runs its own SIGTERM handler.
756778
self.make_file("handler.py", """\

0 commit comments

Comments
 (0)