Skip to content

Commit 4ab4980

Browse files
committed
fix race in tests
1 parent 44628c5 commit 4ab4980

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

auth/auth_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package auth
22

33
import (
44
"errors"
5+
"sync"
56
"testing"
67
"time"
78
)
@@ -47,10 +48,13 @@ func TestStreamingCredentialsProvider(t *testing.T) {
4748

4849
var receivedCreds []Credentials
4950
var receivedErrors []error
51+
var mu sync.Mutex
5052

5153
listener := NewReAuthCredentialsListener(
5254
func(creds Credentials) error {
55+
mu.Lock()
5356
receivedCreds = append(receivedCreds, creds)
57+
mu.Unlock()
5458
return nil
5559
},
5660
func(err error) {
@@ -84,12 +88,14 @@ func TestStreamingCredentialsProvider(t *testing.T) {
8488

8589
// Wait for update to be processed
8690
time.Sleep(100 * time.Millisecond)
91+
mu.Lock()
8792
if len(receivedCreds) != 2 {
8893
t.Fatalf("expected 2 received credentials, got %d", len(receivedCreds))
8994
}
9095
if receivedCreds[1] != newCreds {
9196
t.Fatalf("expected received credential %v, got %v", newCreds, receivedCreds[1])
9297
}
98+
mu.Unlock()
9399

94100
// Cancel subscription
95101
if err := cancel(); err != nil {

0 commit comments

Comments
 (0)