Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure post-suite and destroy execute #238

Merged
merged 2 commits into from
Jan 25, 2024
Merged

Conversation

joshcooper
Copy link
Contributor

When running ci:test:aio make sure beaker exec post-suite executes

When running ci:test:aio[true] make sure beaker destroy executes

Fixes #237

@joshcooper joshcooper requested a review from a team as a code owner January 23, 2024 01:42
@joshcooper joshcooper marked this pull request as draft January 23, 2024 16:34
@joshcooper
Copy link
Contributor Author

We need to run the post-suite even if pre-suite fails (for example in cases where the agent fails to install)

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
```
When running `rake ci:test:aio[true]`, if the post-suite failed and we're not
preserving hosts, then the `beaker destroy` command would be skipped. Use a
nested ensure so the failure of post-suite doesn't prevent `beaker destroy` from
being called.

The nested ensure also guarantees that the `post-suite` will be called even if
the `pre-suite` fails, which can happen if the agent fails to install. This
matches the behavior for the "non-retry" version of the `ci:test:aio` rake task.

```
$ git diff
diff --git a/acceptance/teardown/common/099_Archive_Logs.rb b/acceptance/teardown/common/099_Archive_Logs.rb
index d940e2bea..2302633e1 100644
--- a/acceptance/teardown/common/099_Archive_Logs.rb
+++ b/acceptance/teardown/common/099_Archive_Logs.rb
@@ -1,5 +1,7 @@
 require 'date'

+raise "whoops"
+
 def file_glob(host, path)
   result = on(host, "ls #{path}", :acceptable_exit_codes => [0, 2])
   return [] if result.exit_code != 0

$ 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 teardown/common/099_Archive_Logs.rb
RuntimeError: whoops
...
beaker destroy
```
@joshcooper joshcooper marked this pull request as ready for review January 23, 2024 18:57
@tvpartytonight tvpartytonight merged commit 9536cbb into master Jan 25, 2024
6 checks passed
@tvpartytonight tvpartytonight deleted the ensure-post-suite branch January 25, 2024 00:39
@mhashizume mhashizume added the bug label Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ci:test:aio skips the post-suite if any tests fail, but ci:test:aio[true] doesn't
3 participants