Skip to content

Commit 99d6291

Browse files
authored
test/xds: wait for server to enter SERVING mode before sending the first RPC (#9003)
Fixes #9002 xDS-enabled gRPC servers start accepting connections on the `net.Listener` passed to them, but will close the accepted connections immediately as long as it hasn't yet received good configuration from the management server. This could be the failure the client is seeing in the failing log: ``` xds_server_filter_state_retention_test.go:468: EmptyCall() failed: rpc error: code = Unavailable desc = write tcp 127.0.0.1:38168->127.0.0.1:37463: write: broken pipe ``` This PR fixes the flaky test by waiting for the server to enter `SERVING` mode before sending the first RPC. RELEASE NOTES: none
1 parent 12e91dd commit 99d6291

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

test/xds/xds_server_filter_state_retention_test.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"time"
2929

3030
"google.golang.org/grpc"
31+
"google.golang.org/grpc/connectivity"
3132
"google.golang.org/grpc/credentials/insecure"
3233
"google.golang.org/grpc/internal/resolver"
3334
"google.golang.org/grpc/internal/testutils"
@@ -36,6 +37,7 @@ import (
3637
"google.golang.org/grpc/internal/xds/httpfilter"
3738
testgrpc "google.golang.org/grpc/interop/grpc_testing"
3839
testpb "google.golang.org/grpc/interop/grpc_testing"
40+
"google.golang.org/grpc/xds"
3941
"google.golang.org/protobuf/proto"
4042
"google.golang.org/protobuf/types/known/structpb"
4143
"google.golang.org/protobuf/types/known/wrapperspb"
@@ -175,7 +177,15 @@ func (s) TestServerSideXDS_FilterStateRetention_AcrossUpdates_FilterConfigChange
175177

176178
managementServer, nodeID, bootstrapContents, xdsResolver := setup.ManagementServerAndResolver(t)
177179

178-
lis, stopServer := setupGRPCServer(t, bootstrapContents)
180+
// Wait for the server to enter SERVING mode before making RPCs to avoid
181+
// flakes due to the server closing connections.
182+
servingCh := make(chan struct{})
183+
opt := xds.ServingModeCallback(func(_ net.Addr, args xds.ServingModeChangeArgs) {
184+
if args.Mode == connectivity.ServingModeServing {
185+
close(servingCh)
186+
}
187+
})
188+
lis, stopServer := setupGRPCServer(t, bootstrapContents, opt)
179189
defer stopServer()
180190

181191
host, port, err := hostPortFromListener(lis)
@@ -277,10 +287,15 @@ func (s) TestServerSideXDS_FilterStateRetention_AcrossUpdates_FilterConfigChange
277287
}
278288
defer cc.Close()
279289

280-
client := testgrpc.NewTestServiceClient(cc)
290+
select {
291+
case <-servingCh:
292+
case <-ctx.Done():
293+
t.Fatalf("Timeout waiting for server to enter SERVING mode")
294+
}
281295

282296
// Make an RPC and verify that one filter and two interceptors are created
283297
// (one per filter chain).
298+
client := testgrpc.NewTestServiceClient(cc)
284299
if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil {
285300
t.Fatalf("EmptyCall() failed: %v", err)
286301
}
@@ -389,7 +404,15 @@ func (s) TestServerSideXDS_FilterStateRetention_AcrossUpdates_FilterChainsChange
389404

390405
managementServer, nodeID, bootstrapContents, xdsResolver := setup.ManagementServerAndResolver(t)
391406

392-
lis, stopServer := setupGRPCServer(t, bootstrapContents)
407+
// Wait for the server to enter SERVING mode before making RPCs to avoid
408+
// flakes due to the server closing connections.
409+
servingCh := make(chan struct{})
410+
opt := xds.ServingModeCallback(func(_ net.Addr, args xds.ServingModeChangeArgs) {
411+
if args.Mode == connectivity.ServingModeServing {
412+
close(servingCh)
413+
}
414+
})
415+
lis, stopServer := setupGRPCServer(t, bootstrapContents, opt)
393416
defer stopServer()
394417

395418
host, port, err := hostPortFromListener(lis)
@@ -460,10 +483,15 @@ func (s) TestServerSideXDS_FilterStateRetention_AcrossUpdates_FilterChainsChange
460483
}
461484
defer cc.Close()
462485

463-
client := testgrpc.NewTestServiceClient(cc)
486+
select {
487+
case <-servingCh:
488+
case <-ctx.Done():
489+
t.Fatalf("Timeout waiting for server to enter SERVING mode")
490+
}
464491

465492
// Make an RPC and verify that one filter and one interceptor (for the
466493
// default filter chain) is created.
494+
client := testgrpc.NewTestServiceClient(cc)
467495
if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil {
468496
t.Fatalf("EmptyCall() failed: %v", err)
469497
}

0 commit comments

Comments
 (0)