change healthcheck end2end test

This commit is contained in:
yangzhouhan 2015-06-16 17:11:12 -07:00
Родитель 22c99a7be0
Коммит bd29c7cc2a
2 изменённых файлов: 13 добавлений и 16 удалений

Просмотреть файл

@ -1,6 +1,5 @@
// health is depended on the code generated by protobuf
// For the users who want to implement their own stuff,
// should rewrite this service.
// Package health provides some utility functions to health-check a server. The implementation
// is based on protobuf. Users need to write their own implementations if other IDLs are used.
package health
import (
@ -11,20 +10,19 @@ import (
healthpb "google.golang.org/grpc/health/grpc_health"
)
// HealthCheck is the client side function to health-check a server
func HealthCheck(t time.Duration, cc *grpc.ClientConn) error {
ctx, _ := context.WithTimeout(context.Background(), t)
hc := healthpb.NewHealthCheckClient(cc)
req :=new(healthpb.HealthCheckRequest)
if _,err := hc.Check(ctx, req); err != nil {
return err
}
return nil
req := new(healthpb.HealthCheckRequest)
_, err := hc.Check(ctx, req)
return err
}
type HealthServer struct {
}
func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest)(*healthpb.HealthCheckResponse, error){
func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
out := new(healthpb.HealthCheckResponse)
return out,nil
return out, nil
}

Просмотреть файл

@ -306,7 +306,6 @@ func setUp(healthCheck bool, maxStream uint32, e env) (s *grpc.Server, cc *grpc.
}
s = grpc.NewServer(sopts...)
if healthCheck {
healthpb.RegisterHealthCheckServer(s, &health.HealthServer{})
}
testpb.RegisterTestServiceServer(s, &testServer{})
@ -361,13 +360,13 @@ func testTimeoutOnDeadServer(t *testing.T, e env) {
cc.Close()
}
func TestHealthCheckOnSucceed(t *testing.T) {
func TestHealthCheckOnSuccess(t *testing.T) {
for _, e := range listTestEnv() {
testHealthCheckOnSucceed(t, e)
testHealthCheckOnSuccess(t, e)
}
}
func testHealthCheckOnSucceed(t *testing.T, e env) {
func testHealthCheckOnSuccess(t *testing.T, e env) {
s, cc := setUp(true, math.MaxUint32, e)
defer tearDown(s, cc)
if err := health.HealthCheck(1*time.Second, cc); err != nil {
@ -385,7 +384,7 @@ func testHealthCheckOnFailure(t *testing.T, e env) {
s, cc := setUp(true, math.MaxUint32, e)
defer tearDown(s, cc)
if err := health.HealthCheck(0*time.Second, cc); err != grpc.Errorf(codes.DeadlineExceeded, "context deadline exceeded") {
t.Fatalf("HealthCheck(_)=_, %v, want <DeadlineExcced>", err)
t.Fatalf("HealthCheck(_)=_, %v, want error code %d", err, codes.DeadlineExceeded)
}
}
@ -400,7 +399,7 @@ func testHealthCheckOff(t *testing.T, e env) {
defer tearDown(s, cc)
err := health.HealthCheck(1*time.Second, cc)
if err != grpc.Errorf(codes.Unimplemented, "unknown service grpc.health.HealthCheck") {
t.Fatalf("HealthCheck(_)=_, %v, want <unimplemented>", err)
t.Fatalf("HealthCheck(_)=_, %v, want error code %d", err, codes.DeadlineExceeded)
}
}