Skip to content

Commit

Permalink
Fix tmt run --follow, add test coverage for it
Browse files Browse the repository at this point in the history
Wrong indent in `Run.follow()` introduced in c105887 caused the
`--follow` option to trigger a traceback. Fix the indent and add
basic test coverage to prevent similar regressions in the future.
  • Loading branch information
psss committed Aug 8, 2023
1 parent 5c4ee70 commit 0d17d1e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/run/follow/data/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
10 changes: 10 additions & 0 deletions tests/run/follow/data/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/plan:
discover:
how: fmf
provision:
how: local
execute:
how: tmt

/test:
test: for i in {00..05}; do echo step-$i; sleep 1; done
1 change: 1 addition & 0 deletions tests/run/follow/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
summary: Ensure that following debug log works
25 changes: 25 additions & 0 deletions tests/run/follow/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

rlJournalStart
rlPhaseStartSetup
rlRun "run=\$(mktemp -d)" 0 "Create run directory"
rlRun "pushd data"
rlPhaseEnd

rlPhaseStartTest
rlRun "tmt run --id $run &>/dev/null &" 0 "Start a tmt run in background"
rlRun "sleep 1" 0 "Ignore logging during the first second"
rlRun -s "timeout -s INT 3 tmt run --id $run --follow" 124 "Follow logs for 3 seconds"
rlAssertGrep "step-01" $rlRun_LOG
rlAssertGrep "step-02" $rlRun_LOG
rlAssertNotGrep "step-04" $rlRun_LOG
rlAssertNotGrep "step-05" $rlRun_LOG
rlRun "wait $!" 0 "Wait until the run is finished"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $run" 0 "Remove run directory"
rlPhaseEnd
rlJournalEnd
12 changes: 6 additions & 6 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3102,12 +3102,12 @@ def follow(self) -> None:
if read_lines > FOLLOW_LINES:
break

while True:
line = logfile.readline()
if line:
print(line, end='')
else:
time.sleep(0.5)
while True:
line = logfile.readline()
if line:
print(line, end='')
else:
time.sleep(0.5)

def go(self) -> None:
""" Go and do test steps for selected plans """
Expand Down

0 comments on commit 0d17d1e

Please sign in to comment.