From f1e0525c812eb7097cb61cd01ac3143a84691fae Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Mon, 28 Nov 2016 17:38:40 -0800 Subject: [PATCH] integration: use Range to wait for reboot in quota tests Proxy client layer ignores call options so Put is always FailFast; this can lead to connection errors when trying to issue the Put following restarting the client's target server. --- integration/v3_grpc_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/integration/v3_grpc_test.go b/integration/v3_grpc_test.go index 36c9a9ffd..81fc5c633 100644 --- a/integration/v3_grpc_test.go +++ b/integration/v3_grpc_test.go @@ -595,12 +595,13 @@ func TestV3StorageQuotaAPI(t *testing.T) { defer clus.Terminate(t) kvc := toGRPC(clus.Client(0)).KV + waitForRestart(t, kvc) key := []byte("abc") // test small put that fits in quota smallbuf := make([]byte, 512) - if _, err := kvc.Put(context.TODO(), &pb.PutRequest{Key: key, Value: smallbuf}, grpc.FailFast(false)); err != nil { + if _, err := kvc.Put(context.TODO(), &pb.PutRequest{Key: key, Value: smallbuf}); err != nil { t.Fatal(err) } @@ -643,12 +644,13 @@ func TestV3StorageQuotaApply(t *testing.T) { clus.Members[0].Stop(t) clus.Members[0].Restart(t) clus.waitLeader(t, clus.Members) + waitForRestart(t, kvc0) key := []byte("abc") // test small put still works smallbuf := make([]byte, 1024) - _, serr := kvc0.Put(context.TODO(), &pb.PutRequest{Key: key, Value: smallbuf}, grpc.FailFast(false)) + _, serr := kvc0.Put(context.TODO(), &pb.PutRequest{Key: key, Value: smallbuf}) if serr != nil { t.Fatal(serr) } @@ -1150,3 +1152,14 @@ func TestGRPCStreamRequireLeader(t *testing.T) { func eqErrGRPC(err1 error, err2 error) bool { return !(err1 == nil && err2 != nil) || err1.Error() == err2.Error() } + +// waitForRestart tries a range request until the client's server responds. +// This is mainly a stop-gap function until grpcproxy's KVClient adapter +// (and by extension, clientv3) supports grpc.CallOption pass-through so +// FailFast=false works with Put. +func waitForRestart(t *testing.T, kvc pb.KVClient) { + req := &pb.RangeRequest{Key: []byte("_"), Serializable: true} + if _, err := kvc.Range(context.TODO(), req, grpc.FailFast(false)); err != nil { + t.Fatal(err) + } +}