From eb25340b82a7592e7d01a6610c08cc34ee2a6ba0 Mon Sep 17 00:00:00 2001 From: "Xavier G." Date: Wed, 27 Nov 2024 01:11:15 +0100 Subject: [PATCH] Tests: test_scrolling: reduce the odds of a race condition. --- tests/scripts/scrolling-inside-steps.bash | 2 ++ tests/test_scrolling.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/scripts/scrolling-inside-steps.bash b/tests/scripts/scrolling-inside-steps.bash index 7a8eda6..66f5a9c 100755 --- a/tests/scripts/scrolling-inside-steps.bash +++ b/tests/scripts/scrolling-inside-steps.bash @@ -11,7 +11,9 @@ function output { moulti step add 1 --min-height=10 --max-height=10 --title='Step with auto-scroll enabled by default' moulti step add 2 --min-height=10 --max-height=10 --title='Step with auto-scroll disabled' --no-auto-scroll moulti step add 3 --min-height=10 --max-height=10 --title='Step with auto-scroll enabled by default' + output 40 'interrupted auto-scrolling' | moulti pass 1 & output 40 'no auto-scrolling' | moulti pass 2 & output 40 'auto-scrolling' | moulti pass 3 & +touch "${MOULTI_TEST_BEACON}-output-started" wait diff --git a/tests/test_scrolling.py b/tests/test_scrolling.py index aa44935..ed3d085 100644 --- a/tests/test_scrolling.py +++ b/tests/test_scrolling.py @@ -1,4 +1,4 @@ -from .common import moulti_test, moulti_test_steps, wait_script, wait_script_start, wait_script_end +from .common import Beacon, moulti_test, moulti_test_steps, wait_script, wait_script_start, wait_script_end assert moulti_test def test_programmatic_scrolling(moulti_test): @@ -16,10 +16,19 @@ async def scroll_lock(pilot): await wait_script(pilot) assert moulti_test(command=['manual-scrolling-through-steps.bash'], run_before=scroll_lock) -def test_auto_scrolling(moulti_test): +def test_auto_scrolling(moulti_test, monkeypatch): + beacon = Beacon(monkeypatch) async def interrupt_auto_scroll(pilot): await wait_script_start(pilot) + await beacon.wait(pilot, '-output-started') await pilot.pause(0.5) await pilot.press('tab', 'tab', 'home') # focus the first step, focus its log, hit the 'home' key await wait_script_end(pilot) + # Wait until the first step has finished scrolling back up to the top: + log_widget = pilot.app.steps_container.children[0].log_widget + interval = 0.1 + max_wait = int(45 / interval) + while max_wait and log_widget.scroll_y: + await pilot.pause(interval) + max_wait -= 1 assert moulti_test(command=['scrolling-inside-steps.bash'], run_before=interrupt_auto_scroll)