test: fix GoAwayThenClose by wait for cc state change (#2855)

In the end of the test, 10 RPCs are made to make sure data is sent to
the second server. The first RPC of these 10 is made right after the
second server's listener receives a connection. But at this time, the
connectivity state on the client side is not set to READY yet (though
ac's state should be either connecting or ready, the race between ac
and balancer could cause cc to still be in transient failure). So the
first RPC fails due to transient failure, but the following 9 will
succeed.
This commit is contained in:
Menghan Li
2019-06-13 15:57:55 -07:00
committed by GitHub
parent c7831546a1
commit fc15416d24

View File

@ -7165,6 +7165,11 @@ func (s) TestGoAwayThenClose(t *testing.T) {
t.Fatal("expected the stream to die, but got a successful Recv")
}
// Connection was dialed, so ac is either in connecting or ready. Because there's a race
// between ac state change and balancer state change, so cc could still be transient
// failure. This wait make sure cc is at least in connecting, and RPCs won't fail after
// this.
cc.WaitForStateChange(ctx, connectivity.TransientFailure)
// Do a bunch of RPCs, make sure it stays stable. These should go to connection 2.
for i := 0; i < 10; i++ {
if _, err := client.UnaryCall(ctx, &testpb.SimpleRequest{}); err != nil {