lib/group: fix race condition in test (#39340)

This commit is contained in:
Camden Cheek 2022-07-27 12:06:43 -06:00 committed by GitHub
parent 6e25baf2f7
commit 124dc271a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,6 +98,14 @@ func TestResultErrorGroup(t *testing.T) {
synchronizer := make(chan struct{})
g.Go(func() (int, error) {
<-synchronizer
// This test has an intrinsic race condition that can be reproduced
// by adding a `defer time.Sleep(time.Second)` before the `defer
// close(synchronizer)`. We cannot guarantee that the group processes
// the return value of the second goroutine before the first goroutine
// exits in response to synchronizer, so we add a sleep here to make
// this race condition vanishingly unlikely. Note that this is a race
// in the test, not in the library.
time.Sleep(100 * time.Millisecond)
return 0, err1
})
g.Go(func() (int, error) {