Add TestFailFastRPCWithNoBalancerErrorOnBadCertificates TestNonFailFastRPCWithNoBalancerErrorOnBadCertificates

This commit is contained in:
Menghan Li
2016-07-18 16:00:17 -07:00
parent d7d831d95e
commit 1a571b746a

View File

@ -369,6 +369,7 @@ type test struct {
serverCompression bool
unaryInt grpc.UnaryServerInterceptor
streamInt grpc.StreamServerInterceptor
balancer grpc.Balancer
// srv and srvAddr are set once startServer is called.
srv *grpc.Server
@ -404,6 +405,8 @@ func newTest(t *testing.T, e env) *test {
maxStream: math.MaxUint32,
}
te.ctx, te.cancel = context.WithCancel(context.Background())
// Install roundrobin balancer by default.
te.balancer = grpc.RoundRobin(nil)
return te
}
@ -502,6 +505,9 @@ func (te *test) clientConn() *grpc.ClientConn {
default:
opts = append(opts, grpc.WithInsecure())
}
if te.balancer != nil {
opts = append(opts, grpc.WithBalancer(te.balancer))
}
var err error
te.cc, err = grpc.Dial(te.srvAddr, opts...)
if err != nil {
@ -2317,6 +2323,34 @@ func TestFailFastRPCErrorOnBadCertificates(t *testing.T) {
}
}
func TestFailFastRPCWithNoBalancerErrorOnBadCertificates(t *testing.T) {
te := newTest(t, env{name: "bad-cred", network: "tcp", security: "clientAlwaysFailCred"})
// Uninstall balancer.
te.balancer = nil
te.startServer(&testServer{security: "clientAlwaysFailCred"})
defer te.tearDown()
cc := te.clientConn()
tc := testpb.NewTestServiceClient(cc)
if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}); !strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) {
te.t.Fatalf("Dial(%q) = %v, want err.Error() contains %q", te.srvAddr, err, clientAlwaysFailCredErrorMsg)
}
}
func TestNonFailFastRPCWithNoBalancerErrorOnBadCertificates(t *testing.T) {
te := newTest(t, env{name: "bad-cred", network: "tcp", security: "clientAlwaysFailCred"})
// Uninstall balancer.
te.balancer = nil
te.startServer(&testServer{security: "clientAlwaysFailCred"})
defer te.tearDown()
cc := te.clientConn()
tc := testpb.NewTestServiceClient(cc)
if _, err := tc.EmptyCall(context.Background(), &testpb.Empty{}, grpc.FailFast(false)); !strings.Contains(err.Error(), clientAlwaysFailCredErrorMsg) {
te.t.Fatalf("Dial(%q) = %v, want err.Error() contains %q", te.srvAddr, err, clientAlwaysFailCredErrorMsg)
}
}
// interestingGoroutines returns all goroutines we care about for the purpose
// of leak checking. It excludes testing or runtime ones.
func interestingGoroutines() (gs []string) {