test updates: favor cleanups over defers, and only log from cleanup methods #2043
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.
A few improvements after reading more about best practices and parsing confusing test output:
t.Cleanup()
overdefer
in tests, especially where we run in parallelThis has a few small changes to accomplish this within the runtime tests:
ensureShutdownOnCleanup
helper function to ensure even failing tests call shutdown on the runner. this function does not act as a test, but will log additional info if there is an unexpected failure during shutdownwaitShutdown
, and the differences should be well documented in the codesetupOsqueryInstanceForTests
. tests should test the shutdown methodology withwaitShutdown
(happy path), and rely on the shutdown fromensureShutdownOnCleanup
if anything goes wrong before we get a chance towaitShutdown
testRootDirectory
to log any issues, but not fail the test itself to avoid any confusion (failures here should only be a symptom of some previous issue)