Deflake tests that rely on Stop() then Dial() not reconnecting (#1728)

This commit is contained in:
dfawley
2017-12-13 09:30:53 -08:00
committed by GitHub
parent dba60db4f4
commit d1fc8fa770
4 changed files with 10 additions and 6 deletions

View File

@ -318,7 +318,7 @@ func TestOneServerDown(t *testing.T) {
} }
defer test.cleanup() defer test.cleanup()
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr)) cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr), grpc.WithWaitForHandshake())
if err != nil { if err != nil {
t.Fatalf("failed to dial: %v", err) t.Fatalf("failed to dial: %v", err)
} }
@ -372,6 +372,7 @@ func TestOneServerDown(t *testing.T) {
var targetSeen int var targetSeen int
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
if _, err := testc.EmptyCall(context.Background(), &testpb.Empty{}, grpc.Peer(&p)); err != nil { if _, err := testc.EmptyCall(context.Background(), &testpb.Empty{}, grpc.Peer(&p)); err != nil {
targetSeen = 0
t.Logf("EmptyCall() = _, %v, want _, <nil>", err) t.Logf("EmptyCall() = _, %v, want _, <nil>", err)
// Due to a race, this RPC could possibly get the connection that // Due to a race, this RPC could possibly get the connection that
// was closing, and this RPC may fail. Keep trying when this // was closing, and this RPC may fail. Keep trying when this
@ -415,7 +416,7 @@ func TestAllServersDown(t *testing.T) {
} }
defer test.cleanup() defer test.cleanup()
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr)) cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr), grpc.WithWaitForHandshake())
if err != nil { if err != nil {
t.Fatalf("failed to dial: %v", err) t.Fatalf("failed to dial: %v", err)
} }

View File

@ -332,7 +332,7 @@ func TestOneServerDown(t *testing.T) {
numServers := 2 numServers := 2
servers, r, cleanup := startServers(t, numServers, math.MaxUint32) servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
defer cleanup() defer cleanup()
cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{})) cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}), WithWaitForHandshake())
if err != nil { if err != nil {
t.Fatalf("Failed to create ClientConn: %v", err) t.Fatalf("Failed to create ClientConn: %v", err)
} }
@ -660,7 +660,7 @@ func TestPickFirstOrderOneServerDown(t *testing.T) {
numServers := 3 numServers := 3
servers, r, cleanup := startServers(t, numServers, math.MaxUint32) servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
defer cleanup() defer cleanup()
cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(pickFirstBalancerV1(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{})) cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(pickFirstBalancerV1(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}), WithWaitForHandshake())
if err != nil { if err != nil {
t.Fatalf("Failed to create ClientConn: %v", err) t.Fatalf("Failed to create ClientConn: %v", err)
} }

View File

@ -182,7 +182,7 @@ func TestOneServerDownPickfirst(t *testing.T) {
servers, _, scleanup := startServers(t, numServers, math.MaxInt32) servers, _, scleanup := startServers(t, numServers, math.MaxInt32)
defer scleanup() defer scleanup()
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithBalancerBuilder(newPickfirstBuilder()), WithCodec(testCodec{})) cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithBalancerBuilder(newPickfirstBuilder()), WithCodec(testCodec{}), WithWaitForHandshake())
if err != nil { if err != nil {
t.Fatalf("failed to dial: %v", err) t.Fatalf("failed to dial: %v", err)
} }
@ -224,7 +224,7 @@ func TestAllServersDownPickfirst(t *testing.T) {
servers, _, scleanup := startServers(t, numServers, math.MaxInt32) servers, _, scleanup := startServers(t, numServers, math.MaxInt32)
defer scleanup() defer scleanup()
cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithBalancerBuilder(newPickfirstBuilder()), WithCodec(testCodec{})) cc, err := Dial(r.Scheme()+":///test.server", WithInsecure(), WithBalancerBuilder(newPickfirstBuilder()), WithCodec(testCodec{}), WithWaitForHandshake())
if err != nil { if err != nil {
t.Fatalf("failed to dial: %v", err) t.Fatalf("failed to dial: %v", err)
} }

View File

@ -468,6 +468,7 @@ type test struct {
clientInitialWindowSize int32 clientInitialWindowSize int32
clientInitialConnWindowSize int32 clientInitialConnWindowSize int32
perRPCCreds credentials.PerRPCCredentials perRPCCreds credentials.PerRPCCredentials
customDialOptions []grpc.DialOption
resolverScheme string resolverScheme string
// All test dialing is blocking by default. Set this to true if dial // All test dialing is blocking by default. Set this to true if dial
@ -718,6 +719,7 @@ func (te *test) clientConn() *grpc.ClientConn {
if te.srvAddr == "" { if te.srvAddr == "" {
te.srvAddr = "client.side.only.test" te.srvAddr = "client.side.only.test"
} }
opts = append(opts, te.customDialOptions...)
var err error var err error
te.cc, err = grpc.Dial(scheme+te.srvAddr, opts...) te.cc, err = grpc.Dial(scheme+te.srvAddr, opts...)
if err != nil { if err != nil {
@ -803,6 +805,7 @@ func TestTimeoutOnDeadServer(t *testing.T) {
func testTimeoutOnDeadServer(t *testing.T, e env) { func testTimeoutOnDeadServer(t *testing.T, e env) {
te := newTest(t, e) te := newTest(t, e)
te.customDialOptions = []grpc.DialOption{grpc.WithWaitForHandshake()}
te.userAgent = testAppUA te.userAgent = testAppUA
te.declareLogNoise( te.declareLogNoise(
"transport: http2Client.notifyError got notified that the client transport was broken EOF", "transport: http2Client.notifyError got notified that the client transport was broken EOF",