Structure main_test using the Testify Suite package #169
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.
Motivation / Summary
While the addition of unit tests for
main.gohave been very useful to implement the backoff mechanism (#148) and assess the behaviour of the extension in several edge cases (#136), reliance on package-scoped state variables such asApmServerTransportStateinduces hard-to-detect race conditions.An example is the commit c6b3fb5, whose CI pipeline failed due to a race between the goroutine tasked with setting the
ApmServerTransportStateback topendingand the start ofTestFullChannel. The latter started before the goroutine completed its execution, and none of the events that we supposed to be queued during the test were sent to the APM Server. The issue did not appear in the many commits merged beforehand, with the very same test setup.In an attempt to prevent those races, this PR refactors
main_test.goby using thesuitepackage of testify. This package allows for the definition of aSetupTest()function, that we can use to reset useful variables before each test, hence greatly reducing the risks of unexpected behavior.Files changed
All changes are contained in
main_test.go.How to test
cd apm-lambda-extensiongo test ./.... All tests should pass (with the exception ofe2e_test, which should be skipped).