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

Expose failures to clean up after tests #342

Merged
merged 5 commits into from
Oct 18, 2022

Conversation

squaremo
Copy link
Contributor

@squaremo squaremo commented Oct 18, 2022

When stack objects aren't deleted after tests, it can mean

  • resources created by the stack aren't tidied up;
  • the finalizer logic isn't well tested
  • the stack might interfere in annoying ways with other tests.

Previously, all stacks in the namespace were deleted as part of a top-level AfterEach; but because this tried to delete all stacks and wait until they'd been finalised, any rogue test case that didn't clean up properly and couldn't be finalised would cause some other test to time out.

The first commit here uses a similar idea, but fails the test suite if there are stacks left over at the very end. This highlighted a few problems, which I've also fixed here:

  • a couple of tests were deleting their backend directory before deleting the stack using it, and could fail to be finalized as a result;
  • lots of stacks had random names that didn't help with tracking down the test case
  • some stacks didn't even get deleted after their test case

Deleting a stack but not waiting for it to be finalized, within a test, could mean other tests were "contaminated" (usually only meaning they might take a bit longer, and get cross-talk in the logs, but still). I've made all test cases use a helper which waits for the finalizers to have run.

When stack objects aren't deleted after tests, it can mean

 - resources created by the stack aren't tidied up;
 - the finalizer logic isn't well tested
 - the stack might interfere in annoying ways with other tests.

Previously, all stacks in the namespace were deleted as part of a
top-level `AfterEach`; but because this tried to delete all stacks and
wait until they'd been finalised, any rogue test case that didn't clean
up properly and couldn't be finalised would cause some _other_ test to
time out.

Instead, this commit uses a similar idea, but fails the test suite if
there are stacks left over at the very end. This highlighted a couple of
problems, which I've also fixed here:

 - one test was deleting its working directory before deleting the stack
   using it, and would fail to be finalized;
 - lots of stacks had random names that didn't help with tracking down
   the test case

Finally, the helper `deleteAndWaitForFinalization` can be used to ensure
a test case doesn't exit until it has truly cleaned up. It's worth using
this everywhere -- next, I'm going to rewrite tests to use it, and the
other helpers.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
It's a little bit faster to run a YAML program than to download
dependencies and run a NodeJS program, so this saves a bit of time and
reduces the possibility of timeouts.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
If the controller repeatedly retries a Stack, it will oscillate between
having the "Reconciling" condition because it has been requeued, and
having the same condition because it's being processed by the controller
again.

This makes seeing a specific reason for retrying tricky -- but, if
you've observed that the stack has been processed and failed, then
_either_ reason is good enough to show that it's being retried, so that
race condition can be avoided.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
@squaremo squaremo marked this pull request as ready for review October 18, 2022 16:57
@lblackstone lblackstone added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Oct 18, 2022
@lblackstone lblackstone merged commit 3d0782b into master Oct 18, 2022
@lblackstone lblackstone deleted the do-finalisers-work-properly branch October 18, 2022 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/no-changelog-required This issue doesn't require a CHANGELOG update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants