Skip to content

Commit

Permalink
Fix race condition in TestRollingUpdatesWhenConsumeLogs, for lastReso…
Browse files Browse the repository at this point in the history
…lved

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Aug 12, 2022
1 parent 33c5932 commit 6c060a6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions exporter/loadbalancingexporter/log_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"net"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -342,9 +343,12 @@ func TestRollingUpdatesWhenConsumeLogs(t *testing.T) {
res, err := newDNSResolver(zap.NewNop(), "service-1", "")
require.NoError(t, err)

mu := sync.Mutex{}
var lastResolved []string
res.onChange(func(s []string) {
mu.Lock()
lastResolved = s
mu.Unlock()
})

resolverCh := make(chan struct{}, 1)
Expand Down Expand Up @@ -463,7 +467,9 @@ func TestRollingUpdatesWhenConsumeLogs(t *testing.T) {
<-consumeCh

// verify
mu.Lock()
require.Equal(t, []string{"127.0.0.2"}, lastResolved)
mu.Unlock()
require.Greater(t, counter1.Load(), int64(0))
require.Greater(t, counter2.Load(), int64(0))
}
Expand Down

0 comments on commit 6c060a6

Please sign in to comment.