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

xdsclient: switch xdsclient watch deadlock test to e2e style #5697

Merged
merged 4 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
review comments
  • Loading branch information
easwars committed Nov 4, 2022
commit d086c7aaaa0ac1421ec5132a6a993d5ba5ce415b
11 changes: 4 additions & 7 deletions internal/testutils/xds/e2e/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,10 @@ type ManagementServerOptions struct {
// logic. When the test is done, it should call the Stop() method to cleanup
// resources allocated by the management server.
func StartManagementServer(opts *ManagementServerOptions) (*ManagementServer, error) {
// Create a snapshot cache. The first parameter controls whether the server
// should wait for all resources to be explicitly named in the request
// before responding to any of them.
wait := true
if opts != nil {
wait = !opts.AllowResourceSubset
}
// Create a snapshot cache. The first parameter to NewSnapshotCache()
// controls whether the server should wait for all resources to be
// explicitly named in the request before responding to any of them.
wait := opts == nil || !opts.AllowResourceSubset
cache := v3cache.NewSnapshotCache(wait, v3cache.IDHash{}, serverLogger{})
logger.Infof("Created new snapshot cache...")

Expand Down
25 changes: 10 additions & 15 deletions xds/internal/xdsclient/e2e_test/misc_watchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ import (
v3routepb "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
)

// TestWatchCallAnotherWatch covers the case where watch() is called inline by a
// callback. It makes sure it doesn't cause a deadlock.
// TestWatchCallAnotherWatch tests the scenario where a watch is registered for
// a resource, and more watches are registered from the first watch's callback.
// The test verifies that this scenario does not lead to a deadlock.
func (s) TestWatchCallAnotherWatch(t *testing.T) {
overrideFedEnvVar(t)

// Start an xDS management server and set the option to allow it to respond
// to request which only specify a subset of the configured resources.
// to requests which only specify a subset of the configured resources.
mgmtServer, nodeID, bootstrapContents, _, cleanup := e2e.SetupManagementServer(t, &e2e.ManagementServerOptions{AllowResourceSubset: true})
defer cleanup()

Expand All @@ -47,7 +48,7 @@ func (s) TestWatchCallAnotherWatch(t *testing.T) {
}
defer client.Close()

// Configure the management server to with route configuration resources.
// Configure the management server to respond with route config resources.
resources := e2e.UpdateOptions{
NodeID: nodeID,
Routes: []*v3routepb.RouteConfiguration{
Expand Down Expand Up @@ -76,20 +77,16 @@ func (s) TestWatchCallAnotherWatch(t *testing.T) {
rdsCancel2 = client.WatchRouteConfig(rdsName, func(u xdsresource.RouteConfigUpdate, err error) {
updateCh2.Send(xdsresource.RouteConfigUpdateErrTuple{Update: u, Err: err})
})
t.Cleanup(rdsCancel2)
// Watch for a different resource name.
rdsCancel3 = client.WatchRouteConfig(rdsNameNewStyle, func(u xdsresource.RouteConfigUpdate, err error) {
updateCh3.Send(xdsresource.RouteConfigUpdateErrTuple{Update: u, Err: err})
rdsCancel3()
})
t.Cleanup(rdsCancel3)
})
defer rdsCancel1()
defer func() {
if rdsCancel2 != nil {
rdsCancel2()
}
if rdsCancel3 != nil {
rdsCancel3()
}
}()
// defer rdsCancel1()
t.Cleanup(rdsCancel1)

// Verify the contents of the received update for the all watchers.
wantUpdate12 := xdsresource.RouteConfigUpdateErrTuple{
Expand Down Expand Up @@ -133,6 +130,4 @@ func (s) TestWatchCallAnotherWatch(t *testing.T) {
if err := verifyRouteConfigUpdate(ctx, updateCh3, wantUpdate3); err != nil {
t.Fatal(err)
}
rdsCancel2()
rdsCancel3()
}