Skip to content

Commit

Permalink
Run the report step upon failures as well
Browse files Browse the repository at this point in the history
In order to report at least partial test results, let's execute
the `report` step also when the test run is interrupted in the
middle of the test execution (for example when the guest becomes
unresponsive).
  • Loading branch information
psss committed Jan 13, 2025
1 parent c9b8045 commit f4a7b1a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/report/interrupted/data/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
17 changes: 17 additions & 0 deletions tests/report/interrupted/data/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/plan:
discover:
how: fmf
provision:
how: container
execute:
how: tmt

/test:
test: sleep 5

/1:
summary: Test one
/2:
summary: Test two
/3:
summary: Test three
5 changes: 5 additions & 0 deletions tests/report/interrupted/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
summary: Make sure that report is performed on error
description:
If the run is interrupted in the middle of the test execution,
the report step should still be performed in order to provide
at least partial test results to the user.
26 changes: 26 additions & 0 deletions tests/report/interrupted/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
. /usr/share/beakerlib/beakerlib.sh || exit 1

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

rlPhaseStartTest
tmt run -vvv --id $run 2>$run/output.txt &
pid=$!
sleep 15
container_name=$(grep "container:" $run/plan/provision/guests.yaml | sed -e "s/.*: //")
rlRun "podman container rm -f $container_name"
wait $pid
rlRun "cat $run/output.txt"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlGetTestState || rlFileSubmit "$run/log.txt"
rlRun "rm -r $run" 0 "Remove the run directory"
rlPhaseEnd
rlJournalEnd
7 changes: 5 additions & 2 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2448,8 +2448,11 @@ def go(self) -> None:
self._source_plan_environment_file()
# Make sure we run 'finish' step always if enabled
finally:
if not abort and self.finish.enabled:
self.finish.go()
if not abort:
if self.report.enabled and self.report.status() != "done":
self.report.go()
if self.finish.enabled:
self.finish.go()

def _export(
self,
Expand Down

0 comments on commit f4a7b1a

Please sign in to comment.