-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[testbed] Detect and fix data race at testbed integration test (#30549)
**Description:** Fixing a bug - The Testbed module has many data race warnings when tested with `go test -race`, especially for traces. I've listed the data race issues and fixes below: 1. Add mutex to MockBackend `startedAt` variable Because `tc := testbed.NewTestCase()` starts a `logStats()` goroutine which calls `MockBackend.GetStats()` that uses the `startedAt` variable, a data race occurs when we later execute `tc.StartBackend()`. This is because `tc.StartBackend()` writes to the `startedAt` variable. 2. Add mutex to LoadGenerator `startedAt` variable The reason is similar to MockBackend. 3. Move MockBackend `numSpansReceived` addition after `ConsumeTraces()` Because `tc.numSpansReceived.Add(uint64(td.SpanCount()))` will make `tc.LoadGenerator.DataItemsSent()` equals to `tc.MockBackend.DataItemsReceived()` which the test case will assume MockBackend already received all the spans and lead to `tc.ValidateData()` while MockBackend is actually consuming the traces. 4. Get `td.SpanCount()` before `batchprocessor` consumes the spans at `opencensusreceiver` and `zipkinreceiver` With the `batchprocessor` pipeline, there's a step that it moves the source `td.ResourceSpans()` to the batched one and that is why the `td.SpanCount()` line while `batchprocessor` consuming the traces will cause data race. **Testing:** Add `-race` args to `testbed/runtests.sh` at line 22 where `go test` takes place. Run `TESTS_DIR=correctnesstests/traces make e2e-test` --------- Signed-off-by: James Ryans <[email protected]>
- Loading branch information
1 parent
2107819
commit 95e673e
Showing
4 changed files
with
18 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters