xdsclient/tests: fix flaky test NodeProtoSentOnlyInFirstRequest (#6108)

This commit is contained in:
Easwar Swaminathan 2023-03-10 10:27:04 -08:00 committed by GitHub
parent 3633361c26
commit abd4db22a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 23 deletions

View File

@ -190,12 +190,24 @@ func (s) TestNodeProtoSentOnlyInFirstRequest(t *testing.T) {
} }
defer close() defer close()
// Configure a listener resource on the fake xDS server.
const ( const (
serviceName = "my-service-client-side-xds" serviceName = "my-service-client-side-xds"
routeConfigName = "route-" + serviceName routeConfigName = "route-" + serviceName
clusterName = "cluster-" + serviceName clusterName = "cluster-" + serviceName
) )
// Register a watch for the Listener resource.
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
watcher := xdstestutils.NewTestResourceWatcher()
client.WatchResource(listenerResourceType, serviceName, watcher)
// Ensure the watch results in a discovery request with an empty node proto.
if err := readDiscoveryResponseAndCheckForNonEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil {
t.Fatal(err)
}
// Configure a listener resource on the fake xDS server.
lisAny, err := anypb.New(e2e.DefaultClientListener(serviceName, routeConfigName)) lisAny, err := anypb.New(e2e.DefaultClientListener(serviceName, routeConfigName))
if err != nil { if err != nil {
t.Fatalf("Failed to marshal listener resource into an Any proto: %v", err) t.Fatalf("Failed to marshal listener resource into an Any proto: %v", err)
@ -208,19 +220,16 @@ func (s) TestNodeProtoSentOnlyInFirstRequest(t *testing.T) {
}, },
} }
// Register a watch for the Listener resource. // The xDS client is expected to ACK the Listener resource. The discovery
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) // request corresponding to the ACK must contain a nil node proto.
defer cancel() if err := readDiscoveryResponseAndCheckForEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil {
watcher := xdstestutils.NewTestResourceWatcher()
client.WatchResource(listenerResourceType, serviceName, watcher)
// The first request on the stream must contain a non-empty node proto.
if err := readDiscoveryResponseAndCheckForNonEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// The xDS client is expected to ACK the Listener resource. The discovery // Register a watch for a RouteConfiguration resource.
// request corresponding to the ACK must contain a nil node proto. client.WatchResource(routeConfigResourceType, routeConfigName, watcher)
// Ensure the watch results in a discovery request with an empty node proto.
if err := readDiscoveryResponseAndCheckForEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil { if err := readDiscoveryResponseAndCheckForEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -238,13 +247,7 @@ func (s) TestNodeProtoSentOnlyInFirstRequest(t *testing.T) {
}, },
} }
// Register a watch for a RouteConfiguration resource. Ensure that the // Ensure the discovery request for the ACK contains an empty node proto.
// discovery requests for the route configuration resource and the
// subsequent ACK contains an empty node proto.
client.WatchResource(routeConfigResourceType, routeConfigName, watcher)
if err := readDiscoveryResponseAndCheckForEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil {
t.Fatal(err)
}
if err := readDiscoveryResponseAndCheckForEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil { if err := readDiscoveryResponseAndCheckForEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -262,17 +265,14 @@ func (s) TestNodeProtoSentOnlyInFirstRequest(t *testing.T) {
// The xDS client is expected to re-request previously requested resources. // The xDS client is expected to re-request previously requested resources.
// Hence, we expect two DiscoveryRequest messages (one for the Listener and // Hence, we expect two DiscoveryRequest messages (one for the Listener and
// one for the RouteConfiguration resource). The first message should // one for the RouteConfiguration resource). The first message should contain
// contain a non-nil node proto and second one should contain a nil-proto. // a non-nil node proto and the second should contain a nil-proto.
// //
// And since we don't push any responses on the response channel of the fake // And since we don't push any responses on the response channel of the fake
// server, we do not expect any ACKs here. // server, we do not expect any ACKs here.
if err := readDiscoveryResponseAndCheckForNonEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil { if err := readDiscoveryResponseAndCheckForNonEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// The xDS client is expected to ACK the Listener resource. The discovery
// request corresponding to the ACK must contain a nil node proto.
if err := readDiscoveryResponseAndCheckForEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil { if err := readDiscoveryResponseAndCheckForEmptyNodeProto(ctx, mgmtServer.XDSRequestChan); err != nil {
t.Fatal(err) t.Fatal(err)
} }