Skip to content

Commit

Permalink
Always run post-suite if provision succeeded
Browse files Browse the repository at this point in the history
The `ci:test:aio` rake task would skip the `post-suite` if any presuites or
tests failed. Now the `post-suite` is protected in a nested ensure block so if
`provision` succeeds, then the `post-suite` is guaranteed to be called. This is
important in order to capture failures when installing the agent during the
`pre-suite`.

And due to the nested ensure, if the `post-suite` fails, then `destroy` will
also be guaranteed to be called.

```
$ export BEAKER_PUPPET_VERSION=/home/josh/work/beaker-puppet
$ bundle update
$ bundle exec rake 'ci:test:aio[true]' SHA=8.4.0 TESTS=tests/load_libfacter.rb HOSTS=hosts.yaml
...
Begin tests/load_libfacter.rb

C100161: Ruby can load libfacter without raising an error
RuntimeError: Whoops
/home/josh/work/facter/acceptance/tests/load_libfacter.rb:5
...
beaker exec post-suite
...
Begin teardown/common/099_Archive_Logs.rb
```
  • Loading branch information
joshcooper committed Jan 23, 2024
1 parent 5f0984a commit a8fb322
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tasks/ci.rake
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,14 @@ def beaker_suite(type)
beaker(:provision)

begin
beaker(:exec, 'pre-suite', '--preserve-state', '--pre-suite', pre_suites(type))
beaker(:exec, 'pre-suite', '--preserve-state')
beaker(:exec, ENV.fetch('TESTS', nil))
beaker(:exec, 'post-suite')
begin
beaker(:exec, 'pre-suite', '--preserve-state', '--pre-suite', pre_suites(type))
beaker(:exec, 'pre-suite', '--preserve-state')

beaker(:exec, ENV.fetch('TESTS', nil))
ensure
beaker(:exec, 'post-suite')
end
ensure
preserve_hosts = ENV['OPTIONS'].include?('--preserve-hosts=always') if ENV['OPTIONS']
beaker(:destroy) unless preserve_hosts
Expand Down

0 comments on commit a8fb322

Please sign in to comment.