Skip to content

Commit

Permalink
clusterresolver: Avoid blocking for subsequent resolver updates in te…
Browse files Browse the repository at this point in the history
…st (#7937)
  • Loading branch information
arjan-bal authored Jan 10, 2025
1 parent 9223fd6 commit 62b4867
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions xds/internal/balancer/clusterresolver/e2e_test/eds_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"context"
"errors"
"fmt"
"net"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -1160,17 +1160,17 @@ func (s) TestEDS_EndpointWithMultipleAddresses(t *testing.T) {
return &testpb.SimpleResponse{}, nil
},
}
lis1, err := net.Listen("tcp", "localhost:0")
lis1, err := testutils.LocalTCPListener()
if err != nil {
t.Fatalf("Failed to create listener: %v", err)
}
defer lis1.Close()
lis2, err := net.Listen("tcp", "localhost:0")
lis2, err := testutils.LocalTCPListener()
if err != nil {
t.Fatalf("Failed to create listener: %v", err)
}
defer lis2.Close()
lis3, err := net.Listen("tcp", "localhost:0")
lis3, err := testutils.LocalTCPListener()
if err != nil {
t.Fatalf("Failed to create listener: %v", err)
}
Expand Down Expand Up @@ -1223,7 +1223,8 @@ func (s) TestEDS_EndpointWithMultipleAddresses(t *testing.T) {
defer func() {
balancer.Register(originalRRBuilder)
}()
resolverUpdateCh := make(chan resolver.State, 1)
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 @@ -1232,7 +1233,7 @@ func (s) TestEDS_EndpointWithMultipleAddresses(t *testing.T) {
bd.Data.(balancer.Balancer).Close()
},
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error {
resolverUpdateCh <- ccs.ResolverState
resolverState.Store(&ccs.ResolverState)
return bd.Data.(balancer.Balancer).UpdateClientConnState(ccs)
},
})
Expand Down Expand Up @@ -1297,23 +1298,18 @@ func (s) TestEDS_EndpointWithMultipleAddresses(t *testing.T) {
t.Fatal(err)
}

var rs resolver.State
select {
case rs = <-resolverUpdateCh:
case <-ctx.Done():
t.Fatalf("Context timed out waiting for resolver update.")
}
gotState := resolverState.Load()

gotEndpointPorts := []uint32{}
for _, a := range rs.Endpoints[0].Addresses {
for _, a := range gotState.Endpoints[0].Addresses {
gotEndpointPorts = append(gotEndpointPorts, testutils.ParsePort(t, a.Addr))
}
if diff := cmp.Diff(gotEndpointPorts, tc.wantEndpointPorts); diff != "" {
t.Errorf("Unexpected endpoint address ports in resolver update, diff (-got +want): %v", diff)
}

gotAddrPorts := []uint32{}
for _, a := range rs.Addresses {
for _, a := range gotState.Addresses {
gotAddrPorts = append(gotAddrPorts, testutils.ParsePort(t, a.Addr))
}
if diff := cmp.Diff(gotAddrPorts, tc.wantAddrPorts); diff != "" {
Expand Down

0 comments on commit 62b4867

Please sign in to comment.