Skip to content

Commit 83ef027

Browse files
authored
Fix race in TestExportProtocolViolations_nodelessFirstMessage (#747)
Fix race in TestExportProtocolViolations_nodelessFirstMessage. The race is on the t *testing.T having one of its fields being read and write concurrently. I didn't investigate why this test needs this special timeout handling, just took the obvious fix to protect against the data race - will look at this again later. Fixes #41
1 parent 4bc0aa6 commit 83ef027

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

receiver/opencensusreceiver/octrace/opencensus_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ func TestExportProtocolViolations_nodelessFirstMessage(t *testing.T) {
309309
require.NoError(t, err, "Unexpectedly failed to send the first message: %v", err)
310310

311311
longDuration := 2 * time.Second
312-
testDone := make(chan bool, 1)
312+
testDone := make(chan struct{})
313+
goroutineDone := make(chan struct{})
313314
go func() {
314315
// Our insurance policy to ensure that this test doesn't hang
315316
// forever and should quickly report if/when we regress.
@@ -320,6 +321,7 @@ func TestExportProtocolViolations_nodelessFirstMessage(t *testing.T) {
320321
traceClientDoneFn()
321322
t.Errorf("Test took too long (%s) and is likely still hanging so this is a regression", longDuration)
322323
}
324+
close(goroutineDone)
323325
}()
324326

325327
// Now the response should return an error and should have been torn down
@@ -354,6 +356,7 @@ func TestExportProtocolViolations_nodelessFirstMessage(t *testing.T) {
354356
}
355357

356358
close(testDone)
359+
<-goroutineDone
357360
}
358361

359362
// If the first message is valid (has a non-nil Node) and has spans, those

0 commit comments

Comments
 (0)