Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions xds/internal/resolver/xds_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@ func (s) TestXDSResolverWatchCallbackAfterClose(t *testing.T) {
}
}

// TestXDSResolverCloseClosesXDSClient tests that the XDS resolver's Close
// method closes the XDS client.
func (s) TestXDSResolverCloseClosesXDSClient(t *testing.T) {
xdsC := fakeclient.NewClient()
xdsR, _, cancel := testSetup(t, setupOpts{
xdsClientFunc: func() (xdsClient, error) { return xdsC, nil },
})
defer cancel()
xdsR.Close()
if !xdsC.Closed.HasFired() {
t.Fatalf("xds client not closed by xds resolver Close method")
}
}

// TestXDSResolverBadServiceUpdate tests the case the xdsClient returns a bad
// service update.
func (s) TestXDSResolverBadServiceUpdate(t *testing.T) {
Expand Down
17 changes: 6 additions & 11 deletions xds/internal/testutils/fakeclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package fakeclient
import (
"context"

"google.golang.org/grpc/internal/grpcsync"
"google.golang.org/grpc/internal/testutils"
"google.golang.org/grpc/xds/internal/xdsclient"
"google.golang.org/grpc/xds/internal/xdsclient/bootstrap"
Expand All @@ -41,14 +42,15 @@ type Client struct {
cdsCancelCh *testutils.Channel
edsCancelCh *testutils.Channel
loadReportCh *testutils.Channel
closeCh *testutils.Channel
loadStore *load.Store
bootstrapCfg *bootstrap.Config

ldsCb func(xdsclient.ListenerUpdate, error)
rdsCb func(xdsclient.RouteConfigUpdate, error)
cdsCbs map[string]func(xdsclient.ClusterUpdate, error)
edsCb func(xdsclient.EndpointsUpdate, error)

Closed *grpcsync.Event // fired when Close is called.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Delete closeCh in line 45

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Whoops, lost that part of the cleanup from before. Fixed, thanks.

}

// WatchListener registers a LDS watch.
Expand Down Expand Up @@ -228,16 +230,9 @@ func (xdsC *Client) WaitForReportLoad(ctx context.Context) (ReportLoadArgs, erro
return val.(ReportLoadArgs), err
}

// Close closes the xds client.
// Close fires xdsC.Closed, indicating it was called.
func (xdsC *Client) Close() {
xdsC.closeCh.Send(nil)
}

// WaitForClose waits for Close to be invoked on this client and returns
// context.DeadlineExceeded otherwise.
func (xdsC *Client) WaitForClose(ctx context.Context) error {
_, err := xdsC.closeCh.Receive(ctx)
return err
xdsC.Closed.Fire()
}

// BootstrapConfig returns the bootstrap config.
Expand Down Expand Up @@ -275,8 +270,8 @@ func NewClientWithName(name string) *Client {
cdsCancelCh: testutils.NewChannelWithSize(10),
edsCancelCh: testutils.NewChannel(),
loadReportCh: testutils.NewChannel(),
closeCh: testutils.NewChannel(),
loadStore: load.NewStore(),
cdsCbs: make(map[string]func(xdsclient.ClusterUpdate, error)),
Closed: grpcsync.NewEvent(),
}
}