Fixing some data races exposed during unit testing#319
Conversation
- utilizes a `sync.Once` struct to make sure a set of global vars is initialized only once.
- adds context done monitor to monitor goroutine to allow canceling the routine from tests.
| r.Log.V(logger.InfoLevel).Info("Start monitoring replication-group") | ||
|
|
||
| dellCSIReplicationGroupsList := new(repv1.DellCSIReplicationGroupList) | ||
| select { |
There was a problem hiding this comment.
Annotation: this whole function's indentation was decreased because the ticker was pulled from here, to the Monitor() function above, but the diff makes it look more complicated than that, unfortunately.
Pulling that ticker up allows us to use a select statement on the ticker and the ctx.Done channels, allowing us to exit as soon as ctx.Done is selected, instead of pre-loading or queuing this function by default and waiting for the ticker to tick, running the function and then finding out ctx.Done is done.
Merging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
Description
Intermittent data race warnings were being reported when running unit tests from the GitHub Actions.
Investigation showed there are several instances where
InitLabelsAndAnnotations()is called from test code while other routines are running that concurrently access these label vars, causing the data race.With the current implementation, a data race here should not be a concern, because the
InitLabelsAndAnnotations()func is called once from main to set/build the label values, then they are only ever read, never written-to again, until it comes to the test code as mentioned above.Changes allow the Replication Group monitor loop goroutine to be canceled using the provided context. Tests that are finished using the monitor loop should defer a call to the context's
cancel()func for the context provided to the(*ReplicationGroupMonitor).Monitor()function.GitHub Issues
Checklist:
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Please also list any relevant details for your test configuration