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

want generic framework for common saga tests #3896

Closed
gjcolombo opened this issue Aug 17, 2023 · 1 comment · Fixed by #3904
Closed

want generic framework for common saga tests #3896

gjcolombo opened this issue Aug 17, 2023 · 1 comment · Fixed by #3904
Assignees
Labels
nexus Related to nexus Testing & Analysis Tests & Analyzers

Comments

@gjcolombo
Copy link
Contributor

There are several common tests that we rewrite for several different sagas, e.g.:

  • test that the saga runs correctly
  • test that the saga unwinds correctly from each possible error injection point
  • test that the saga runs correctly if an arbitrary node is repeated
  • test that the saga unwinds correctly if arbitrary undo nodes are repeated

An important lesson from #3265 and #3894 is that these tests, especially the second kind, are hard to write correctly: it's easy to get the saga execution boilerplate wrong so that the test passes but not all the undo actions are properly tested. It's also easy to forget to regenerate saga parameters that may have been changed by a prior attempt to execute the saga.

Instead of rewriting these tests by hand each time we write a new saga, we should write a set of templated harnesses that let the caller specify how to produce a DAG for each execution of the saga and what (if any) actions should be taken after each execution. Then the harness does the work of executing the saga, injecting retries/undo steps, checking for the correct errors, and the like, calling the caller-supplied closures on either side to ensure the correct parameters are generated for each test run.

@gjcolombo gjcolombo added Testing & Analysis Tests & Analyzers nexus Related to nexus labels Aug 17, 2023
@jordanhendricks
Copy link
Contributor

It seems like #1799 might have some overlap here.

@gjcolombo gjcolombo self-assigned this Aug 18, 2023
gjcolombo added a commit that referenced this issue Aug 24, 2023
Several of our saga undo tests have previously been found to have
defects in which the test verifies that all attempts to execute a saga
fail but doesn't verify that saga executions fail at the expected
failure point. This loses test coverage, since the tests don't actually
execute all of the undo actions of the saga under test.

To try to prevent this problem, add a set of saga test helpers that
provide common logic for writing undo tests. The scaffold functions
handle the business of constructing a DAG, deciding where to inject an
error, and verifying that errors occur in the right places. The callers
provide a saga type and factory functions that run before and after each
saga execution to set up state, provide saga parameters, check
invariants, and clean up after each test iteration.

Convert existing tests of these types to use the new scaffolds. This
revealed that the no-pantry version of the disk snapshot test has a
similar bug: the saga requires the disk being snapshotted to be attached
to an instance, but the test wasn't creating an instance, so the saga
never got past its "look up the instance that owns the disk" step. Fix
this issue.

Add an additional scaffold that repeats nodes in a successful saga. This
case is less fragile than the undo case, but this gets rid of some
copy-pasted code.

Finally, coalesce some common instance operations (start, stop, delete,
simulate) that were used by multiple saga tests into the test helpers.

This is a test-only change, tested both by running `cargo test` and
finding no errors and by introducing bugs into some sagas and verifying
that tests run with the scaffolds catch those bugs.

Fixes #3896.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nexus Related to nexus Testing & Analysis Tests & Analyzers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants