Skip to content

Commit

Permalink
Use atomic pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan-bal committed Dec 24, 2024
1 parent bb960bf commit 8d114e6
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions xds/internal/balancer/clusterresolver/e2e_test/eds_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -1223,8 +1223,8 @@ func (s) TestEDS_EndpointWithMultipleAddresses(t *testing.T) {
defer func() {
balancer.Register(originalRRBuilder)
}()
resolverStateMu := sync.Mutex{}
resolverState := resolver.State{}
resolverState := atomic.Pointer[resolver.State]{}
resolverState.Store(&resolver.State{})
stub.Register(roundrobin.Name, stub.BalancerFuncs{
Init: func(bd *stub.BalancerData) {
bd.Data = originalRRBuilder.Build(bd.ClientConn, bd.BuildOptions)
Expand All @@ -1233,9 +1233,7 @@ func (s) TestEDS_EndpointWithMultipleAddresses(t *testing.T) {
bd.Data.(balancer.Balancer).Close()
},
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {
resolverStateMu.Lock()
defer resolverStateMu.Unlock()
resolverState = ccs.ResolverState
resolverState.Store(&ccs.ResolverState)
return bd.Data.(balancer.Balancer).UpdateClientConnState(ccs)
},
})
Expand Down Expand Up @@ -1300,9 +1298,7 @@ func (s) TestEDS_EndpointWithMultipleAddresses(t *testing.T) {
t.Fatal(err)
}

resolverStateMu.Lock()
gotState := resolverState
resolverStateMu.Unlock()
gotState := resolverState.Load()

gotEndpointPorts := []uint32{}
for _, a := range gotState.Endpoints[0].Addresses {
Expand Down

0 comments on commit 8d114e6

Please sign in to comment.