test: fix flake in GoAwayThenClose (#3052)
In the event of a race, the first server may not be fully serving before the client attempt to connect, then the second server may attempt to field the FullDuplexCall, which it does not implement. Fix the race by giving the client only the first server's address until after the FullDuplexCall is started.
This commit is contained in:
@ -7113,7 +7113,7 @@ func (s) TestGoAwayThenClose(t *testing.T) {
|
||||
}
|
||||
s1 := grpc.NewServer()
|
||||
defer s1.Stop()
|
||||
ts1 := &funcServer{
|
||||
ts := &funcServer{
|
||||
unaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||
return &testpb.SimpleResponse{}, nil
|
||||
},
|
||||
@ -7126,7 +7126,7 @@ func (s) TestGoAwayThenClose(t *testing.T) {
|
||||
return err
|
||||
},
|
||||
}
|
||||
testpb.RegisterTestServiceServer(s1, ts1)
|
||||
testpb.RegisterTestServiceServer(s1, ts)
|
||||
go s1.Serve(lis1)
|
||||
|
||||
conn2Established := grpcsync.NewEvent()
|
||||
@ -7136,17 +7136,13 @@ func (s) TestGoAwayThenClose(t *testing.T) {
|
||||
}
|
||||
s2 := grpc.NewServer()
|
||||
defer s2.Stop()
|
||||
ts2 := &funcServer{unaryCall: func(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||
return &testpb.SimpleResponse{}, nil
|
||||
}}
|
||||
testpb.RegisterTestServiceServer(s2, ts2)
|
||||
testpb.RegisterTestServiceServer(s2, ts)
|
||||
go s2.Serve(lis2)
|
||||
|
||||
r, rcleanup := manual.GenerateAndRegisterManualResolver()
|
||||
defer rcleanup()
|
||||
r.InitialState(resolver.State{Addresses: []resolver.Address{
|
||||
{Addr: lis1.Addr().String()},
|
||||
{Addr: lis2.Addr().String()},
|
||||
}})
|
||||
cc, err := grpc.DialContext(ctx, r.Scheme()+":///", grpc.WithInsecure())
|
||||
if err != nil {
|
||||
@ -7163,6 +7159,11 @@ func (s) TestGoAwayThenClose(t *testing.T) {
|
||||
t.Fatalf("FullDuplexCall(_) = _, %v; want _, nil", err)
|
||||
}
|
||||
|
||||
r.UpdateState(resolver.State{Addresses: []resolver.Address{
|
||||
{Addr: lis1.Addr().String()},
|
||||
{Addr: lis2.Addr().String()},
|
||||
}})
|
||||
|
||||
// Send GO_AWAY to connection 1.
|
||||
go s1.GracefulStop()
|
||||
|
||||
|
Reference in New Issue
Block a user