Skip to content

Commit 8fa9901

Browse files
committed
test: fix data race in NewWatcher test
Goroutines could set a value to `ret` shared variable without protection. The shared variable has been replaced with a channel. Part of #284
1 parent 4871044 commit 8fa9901

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tarantool_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,7 +3835,7 @@ func TestConnection_NewWatcher_concurrent(t *testing.T) {
38353835
var wg sync.WaitGroup
38363836
wg.Add(testConcurrency)
38373837

3838-
var ret error
3838+
errors := make(chan error, testConcurrency)
38393839
for i := 0; i < testConcurrency; i++ {
38403840
go func(i int) {
38413841
defer wg.Done()
@@ -3846,21 +3846,22 @@ func TestConnection_NewWatcher_concurrent(t *testing.T) {
38463846
close(events)
38473847
})
38483848
if err != nil {
3849-
ret = err
3849+
errors <- err
38503850
} else {
38513851
select {
38523852
case <-events:
38533853
case <-time.After(time.Second):
3854-
ret = fmt.Errorf("Unable to get an event %d", i)
3854+
errors <- fmt.Errorf("Unable to get an event %d", i)
38553855
}
38563856
watcher.Unregister()
38573857
}
38583858
}(i)
38593859
}
38603860
wg.Wait()
3861+
close(errors)
38613862

3862-
if ret != nil {
3863-
t.Fatalf("An error found: %s", ret)
3863+
for err := range errors {
3864+
t.Errorf("An error found: %s", err)
38643865
}
38653866
}
38663867

0 commit comments

Comments
 (0)