Give ShotoverProcess powerful event assertions by parsing JSON events #950
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
The goal of this PR is to allow making assertions on what tracing events occur during integration tests.
At first I wanted to do this with ShotoverManager by routing tracing events directly into a Vec.
However after thinking about it I realized there were a lot of advantages to instead using ShotoverProcess for this.
Advantages to replacing ShotoverManager with ShotoverProcess
#[cfg(feature = "alpha-transforms")]
because the binary is always compiled with --all-features--show-output
The only disadvantage I can think of is losing the strong typing in the boundary between tests and shotover i.e. we go from calling rust code to executing a binary
Advantages to implementing event assertions on ShotoverProcess instead of ShotoverManager:
The only disadvantage I can think of is that we cant assert on logs from the test logic, but tbh thats acceptable because most of the time we want to assert on Shotovers events not the tests.
Approach
I renamed ShotoverProcess to BinProcess and moved it into a new crate tokio-bin-process.
The goal is to have it as a reusable crate that other projects can take advantage of.
To that end I have kept anything shotover specific out of that crate, and then made some small shotover specific wrappers in
test-helpers/shotover_process.rs
Once we are happy with tokio-bin-process for our own usage we should move it into its own repo, for now keeping it in shotover-proxy helps us move quickly.
test_shotover_shutdown_when_topology_invalid_topology_subchains is a good example of what it looks like when we have some warnings/errors to allow.
A BinProcess enforces that it is properly shutdown in its drop implementation.
To properly shutdown a BinProcess the users calls a shutdown method such as
shutdown_and_then_consume_events
.When this occurs BinProcess asserts that no error or warning events occurred.
If the user specifically desires that a warning or error occurs then they can provide EventMatcher's to
shutdown_and_then_consume_events
to describe which events they want to allow.It is quite flexible but we will want developers to be as specific as possible when writing EventMatcher's
I would just review all the tokio-bin-process code from scratch as it has changed so drastically from the original ShotoverProcess code.
Future work
Future work can be split up into the following PRs:
#[cfg(feature = "alpha-transforms")]
)#[path ...]
hacks in tests and benchmarks.