Skip to content

Commit

Permalink
Tests: test_scrolling: reduce the odds of a race condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierog committed Nov 27, 2024
1 parent 81049df commit eb25340
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests/scripts/scrolling-inside-steps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions tests/test_scrolling.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)

0 comments on commit eb25340

Please sign in to comment.