Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/ffpuppet/process_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def dump_coverage(self, timeout: int = 15, idle_wait: int = 2) -> bool:
idle_wait: Number of seconds to wait to determine if update is complete.

Returns:
True if coverage is written to disk otherwise False.
True if coverage is written to disk or processes exit otherwise False.
"""
assert COVERAGE_SIGNAL is not None
assert getenv("GCOV_PREFIX_STRIP"), "GCOV_PREFIX_STRIP not set"
Expand All @@ -181,13 +181,15 @@ def dump_coverage(self, timeout: int = 15, idle_wait: int = 2) -> bool:
pass
# no processes signaled
if signaled == 0:
LOG.warning("Coverage signal not sent, no browser processes found")
return False
LOG.debug("coverage signal not sent, no browser processes found")
return True
# wait for processes to write .gcda files (typically takes ~2 seconds)
start_time = perf_counter()
last_change = None
success = False
while self.is_running():
while True:
if not self.is_running():
LOG.debug("not running waiting for coverage dump")
return True
# collect latest last modified dates
mdate = _last_modified(cov_path) or 0
# check if gcda files have been updated
Expand All @@ -203,8 +205,7 @@ def dump_coverage(self, timeout: int = 15, idle_wait: int = 2) -> bool:
and not _writing_coverage(self.processes())
):
LOG.debug("coverage (gcda) dump took %0.2fs", elapsed)
success = True
break
return True
# check if max duration has been exceeded
if elapsed >= timeout:
if last_change is None:
Expand All @@ -213,7 +214,7 @@ def dump_coverage(self, timeout: int = 15, idle_wait: int = 2) -> bool:
LOG.warning("Coverage file open after %0.2fs", elapsed)
break
sleep(0.25)
return success
return False

def is_running(self) -> bool:
"""Check if parent process is running.
Expand Down
16 changes: 9 additions & 7 deletions src/ffpuppet/test_process_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,21 @@ def test_process_tree_04(mocker):


@mark.parametrize(
"procs, last_mod, writing, success",
"procs, last_mod, writing, is_running, success",
[
# no processes
(False, repeat(0), False, False),
(False, repeat(0), False, True, True),
# data written successfully
(True, chain([0], repeat(2)), False, True),
(True, chain([0], repeat(2)), False, True, True),
# data not updated
(True, repeat(0), False, False),
(True, repeat(0), False, True, False),
# data write timeout
(True, chain([0], repeat(2)), True, False),
(True, chain([0], repeat(2)), True, True, False),
# process exits
(True, repeat(0), False, False, True),
],
)
def test_process_tree_05(mocker, procs, last_mod, writing, success):
def test_process_tree_05(mocker, procs, last_mod, writing, is_running, success):
"""test ProcessTree.dump_coverage()"""
mocker.patch("ffpuppet.process_tree.COVERAGE_SIGNAL", return_value="foo")
mocker.patch("ffpuppet.process_tree.getenv", return_value="foo")
Expand All @@ -207,7 +209,7 @@ def __init__(self):
pass

def is_running(self) -> bool:
return True
return is_running

def processes(self, recursive=False):
return [] if not procs else [mocker.Mock(spec_set=Process)]
Expand Down