chore: fix unit test data races (#3478) #3479
Merged
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.
Fixes #3478
See parent issue for reproduction steps.
With this set of changes,
go test -race (...)
now passes:(I also used this shell script to run the tests over and over for several hours, to ensure there are not remaining intermittent failures).
Data races fixed
Unsynchronized read/write to 'callbacks' within
pkg/kubectl-argo-rollouts/viewcontroller/viewcontroller.go
Unsynchronized read/writes to 'rolloutUpdates' within
pkg/kubectl-argo-rollouts/cmd/get/get_rollout.go
:Unsynchronized read/write to 'enqueuedObjects' in various test functions
Unsynchronized read/write to
utils/time
's Now global variable, which is used by unit tests to simulate time changes by replacing default time.Now()Ambassador unit test's fake client was allowing unintended modification of the mock object in memory, via k8s client Get() function
APISix unit tests cannot be parallelized, due to the use of 4 global test variables that are shared between test threads in
rollout/trafficrouting/apisix/mocks/apisix.go
:Fix:
APIsix unit tests cannot share a single, global reference to
client *mocks.FakeClient
, when parallelizedTraefik unit tests also cannot share a single, global reference to
client *mocks.FakeClient
, when parallelizedTraefik unit tests cannot be parallelized, due to the use of 2 global test variables that are shared between test threads in
rollout/trafficrouting/traefik/mocks/traefik.go
:Fix:
Unsynchronized read/write to events in
FakeEventRecorder
A small number of miscellaneous tests that were not using mutexes when read/writing between go routines
Checklist:
"fix(controller): Updates such and such. Fixes #1234"
.