Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from profiling.sampling.live_collector import LiveStatsCollector, MockDisplay
from profiling.sampling.cli import main
from profiling.sampling.sample import _is_process_running
from ._live_collector_helpers import (
MockThreadInfo,
MockInterpreterInfo,
Expand Down Expand Up @@ -825,17 +826,28 @@ def test_get_all_lines_full_display(self):
class TestLiveModeErrors(unittest.TestCase):
"""Tests running error commands in the live mode fails gracefully."""

class QuitWhenTargetExitsDisplay(MockDisplay):
def __init__(self, pid):
super().__init__()
self.pid = pid

def get_input(self):
ch = super().get_input()
if ch != -1:
return ch
if not _is_process_running(self.pid):
return ord('q')
return -1

def mock_curses_wrapper(self, func):
func(mock.MagicMock())

def mock_init_curses_side_effect(self, n_times, mock_self, stdscr):
mock_self.display = MockDisplay()
# Allow the loop to run for a bit (approx 0.5s) before quitting
# This ensures we don't exit too early while the subprocess is
# still failing
mock_self.display = self.QuitWhenTargetExitsDisplay(mock_self.pid)
# Feed non-input events so live mode keeps polling until the target
# process exits and its stderr can be reported.
for _ in range(n_times):
mock_self.display.simulate_input(-1)
mock_self.display.simulate_input(ord('q'))

def test_run_failed_module_live(self):
"""Test that running a existing module that fails exits with clean error."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Avoid prematurely terminating failing live sampling profiler test targets,
which made stderr assertions flaky on ASAN buildbots.
Loading