Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clusterresolver: Avoid blocking for subsequent resolver updates in test #7937

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more concise and express the same thing if it used an atomic.Pointer instead of a separate mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use an atomic pointer.

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
Loading