diff --git a/auth/store_test.go b/auth/store_test.go index 67e50f23ff6..dc6cf3b7b91 100644 --- a/auth/store_test.go +++ b/auth/store_test.go @@ -751,10 +751,10 @@ func TestHammerSimpleAuthenticate(t *testing.T) { token := fmt.Sprintf("%s(%d)", user, i) ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, token) if _, err := as.Authenticate(ctx, user, "123"); err != nil { - t.Fatal(err) + t.Error(err) } if _, err := as.AuthInfoFromCtx(ctx); err != nil { - t.Fatal(err) + t.Error(err) } }(u) } diff --git a/client/client.go b/client/client.go index 6f1270f8a2a..de9ab798e48 100644 --- a/client/client.go +++ b/client/client.go @@ -640,11 +640,11 @@ func (r *redirectFollowingHTTPClient) Do(ctx context.Context, act httpAction) (* if resp.StatusCode/100 == 3 { hdr := resp.Header.Get("Location") if hdr == "" { - return nil, nil, fmt.Errorf("Location header not set") + return nil, nil, fmt.Errorf("location header not set") } loc, err := url.Parse(hdr) if err != nil { - return nil, nil, fmt.Errorf("Location header not valid URL: %s", hdr) + return nil, nil, fmt.Errorf("location header not valid URL: %s", hdr) } next = &redirectedHTTPAction{ action: act, diff --git a/client/client_test.go b/client/client_test.go index c66d3b77b57..a84e0ba0c29 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -691,7 +691,7 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { }, }, }, - wantErr: errors.New("Location header not set"), + wantErr: errors.New("location header not set"), }, // fail if Location header is invalid @@ -707,7 +707,7 @@ func TestRedirectFollowingHTTPClient(t *testing.T) { }, }, }, - wantErr: errors.New("Location header not valid URL: :"), + wantErr: errors.New("location header not valid URL: :"), }, // fail if redirects checked way too many times @@ -795,7 +795,7 @@ func TestHTTPClusterClientSync(t *testing.T) { want = []string{"http://127.0.0.1:2379", "http://127.0.0.1:4001", "http://127.0.0.1:4002", "http://127.0.0.1:4003"} got = hc.Endpoints() - sort.Sort(sort.StringSlice(got)) + sort.Strings(got) if !reflect.DeepEqual(want, got) { t.Fatalf("incorrect endpoints post-Sync: want=%#v got=%#v", want, got) } diff --git a/client/keys.go b/client/keys.go index 22874624183..4b161d11557 100644 --- a/client/keys.go +++ b/client/keys.go @@ -66,7 +66,7 @@ func (e Error) Error() string { } var ( - ErrInvalidJSON = errors.New("client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint.") + ErrInvalidJSON = errors.New("client: response is invalid json. The endpoint is probably not valid etcd cluster endpoint") ErrEmptyBody = errors.New("client: response body is empty") ) diff --git a/clientv3/balancer/balancer.go b/clientv3/balancer/balancer.go index 25dc2b7e730..56693474fc2 100644 --- a/clientv3/balancer/balancer.go +++ b/clientv3/balancer/balancer.go @@ -224,7 +224,6 @@ func (bb *baseBalancer) HandleSubConnStateChange(sc balancer.SubConn, s connecti } bb.currentConn.UpdateBalancerState(bb.currentState, bb.Picker) - return } func (bb *baseBalancer) regeneratePicker() { diff --git a/clientv3/balancer/grpc1.7-health.go b/clientv3/balancer/grpc1.7-health.go index 7d24b93f628..0beed8a8734 100644 --- a/clientv3/balancer/grpc1.7-health.go +++ b/clientv3/balancer/grpc1.7-health.go @@ -507,7 +507,7 @@ func (b *GRPC17Health) Get(ctx context.Context, opts grpc.BalancerGetOptions) (g addr = b.pinAddr b.mu.RUnlock() if closed { - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing + return grpc.Address{Addr: ""}, nil, context.Canceled } if addr == "" { return grpc.Address{Addr: ""}, nil, ErrNoAddrAvilable @@ -522,7 +522,7 @@ func (b *GRPC17Health) Get(ctx context.Context, opts grpc.BalancerGetOptions) (g select { case <-ch: case <-b.donec: - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing + return grpc.Address{Addr: ""}, nil, context.Canceled case <-ctx.Done(): return grpc.Address{Addr: ""}, nil, ctx.Err() } @@ -532,7 +532,7 @@ func (b *GRPC17Health) Get(ctx context.Context, opts grpc.BalancerGetOptions) (g b.mu.RUnlock() // Close() which sets b.closed = true can be called before Get(), Get() must exit if balancer is closed. if closed { - return grpc.Address{Addr: ""}, nil, grpc.ErrClientConnClosing + return grpc.Address{Addr: ""}, nil, context.Canceled } if addr != "" { break diff --git a/clientv3/balancer/grpc1.7-health_test.go b/clientv3/balancer/grpc1.7-health_test.go index bb4f7b8a861..5e1793548b9 100644 --- a/clientv3/balancer/grpc1.7-health_test.go +++ b/clientv3/balancer/grpc1.7-health_test.go @@ -281,7 +281,7 @@ func (kcl *killConnListener) listen(l net.Listener) { default: } if err != nil { - kcl.t.Fatal(err) + kcl.t.Error(err) } time.Sleep(1 * time.Millisecond) conn.Close() diff --git a/clientv3/client.go b/clientv3/client.go index e668607919b..d93b64c4356 100644 --- a/clientv3/client.go +++ b/clientv3/client.go @@ -627,7 +627,9 @@ func toErr(ctx context.Context, err error) error { } case codes.Unavailable: case codes.FailedPrecondition: - err = grpc.ErrClientConnClosing + if ctx.Err() != nil { + err = ctx.Err() + } } } return err diff --git a/clientv3/concurrency/election_test.go b/clientv3/concurrency/election_test.go index 0e45d91ed6a..4a187c823ed 100644 --- a/clientv3/concurrency/election_test.go +++ b/clientv3/concurrency/election_test.go @@ -67,19 +67,13 @@ func TestResumeElection(t *testing.T) { go func() { o := e.Observe(ctx) respChan <- nil - for { - select { - case resp, ok := <-o: - if !ok { - t.Fatal("Observe() channel closed prematurely") - } - // Ignore any observations that candidate1 was elected - if string(resp.Kvs[0].Value) == "candidate1" { - continue - } - respChan <- &resp - return + for resp := range o { + // Ignore any observations that candidate1 was elected + if string(resp.Kvs[0].Value) == "candidate1" { + continue } + respChan <- &resp + return } }() diff --git a/clientv3/doc.go b/clientv3/doc.go index 01a3f5961a7..3a547195476 100644 --- a/clientv3/doc.go +++ b/clientv3/doc.go @@ -90,7 +90,7 @@ // // with etcd clientv3 <= v3.3 // if err == context.Canceled { // // grpc balancer calls 'Get' with an inflight client.Close -// } else if err == grpc.ErrClientConnClosing { +// } else if err == codes.Canceled { // // grpc balancer calls 'Get' after client.Close. // } // // with etcd clientv3 >= v3.4 diff --git a/clientv3/integration/kv_test.go b/clientv3/integration/kv_test.go index e8d22e538f0..55fca0795e3 100644 --- a/clientv3/integration/kv_test.go +++ b/clientv3/integration/kv_test.go @@ -29,8 +29,8 @@ import ( "go.etcd.io/etcd/mvcc/mvccpb" "go.etcd.io/etcd/pkg/testutil" - "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) func TestKVPutError(t *testing.T) { @@ -448,7 +448,7 @@ func TestKVGetErrConnClosed(t *testing.T) { defer close(donec) _, err := cli.Get(context.TODO(), "foo") if !clientv3.IsConnCanceled(err) { - t.Fatalf("expected %v or %v, got %v", context.Canceled, grpc.ErrClientConnClosing, err) + t.Errorf("expected %v or %v, got %v", context.Canceled, codes.Canceled, err) } }() @@ -475,7 +475,7 @@ func TestKVNewAfterClose(t *testing.T) { go func() { _, err := cli.Get(context.TODO(), "foo") if !clientv3.IsConnCanceled(err) { - t.Fatalf("expected %v or %v, got %v", context.Canceled, grpc.ErrClientConnClosing, err) + t.Errorf("expected %v or %v, got %v", context.Canceled, codes.Canceled, err) } close(donec) }() @@ -689,7 +689,7 @@ func TestKVGetRetry(t *testing.T) { // Get will fail, but reconnect will trigger gresp, gerr := kv.Get(ctx, "foo") if gerr != nil { - t.Fatal(gerr) + t.Error(gerr) } wkvs := []*mvccpb.KeyValue{ { @@ -701,7 +701,7 @@ func TestKVGetRetry(t *testing.T) { }, } if !reflect.DeepEqual(gresp.Kvs, wkvs) { - t.Fatalf("bad get: got %v, want %v", gresp.Kvs, wkvs) + t.Errorf("bad get: got %v, want %v", gresp.Kvs, wkvs) } donec <- struct{}{} }() @@ -739,10 +739,10 @@ func TestKVPutFailGetRetry(t *testing.T) { // Get will fail, but reconnect will trigger gresp, gerr := kv.Get(context.TODO(), "foo") if gerr != nil { - t.Fatal(gerr) + t.Error(gerr) } if len(gresp.Kvs) != 0 { - t.Fatalf("bad get kvs: got %+v, want empty", gresp.Kvs) + t.Errorf("bad get kvs: got %+v, want empty", gresp.Kvs) } donec <- struct{}{} }() @@ -908,7 +908,7 @@ func TestKVLargeRequests(t *testing.T) { maxCallSendBytesClient: 10 * 1024 * 1024, maxCallRecvBytesClient: 0, valueSize: 10 * 1024 * 1024, - expectError: grpc.Errorf(codes.ResourceExhausted, "trying to send message larger than max "), + expectError: status.Errorf(codes.ResourceExhausted, "trying to send message larger than max "), }, { maxRequestBytesServer: 10 * 1024 * 1024, @@ -922,7 +922,7 @@ func TestKVLargeRequests(t *testing.T) { maxCallSendBytesClient: 10 * 1024 * 1024, maxCallRecvBytesClient: 0, valueSize: 10*1024*1024 + 5, - expectError: grpc.Errorf(codes.ResourceExhausted, "trying to send message larger than max "), + expectError: status.Errorf(codes.ResourceExhausted, "trying to send message larger than max "), }, } for i, test := range tests { diff --git a/clientv3/integration/lease_test.go b/clientv3/integration/lease_test.go index 6fd8f4306aa..9b383c6f31c 100644 --- a/clientv3/integration/lease_test.go +++ b/clientv3/integration/lease_test.go @@ -28,7 +28,7 @@ import ( "go.etcd.io/etcd/integration" "go.etcd.io/etcd/pkg/testutil" - "google.golang.org/grpc" + "google.golang.org/grpc/codes" ) func TestLeaseNotFoundError(t *testing.T) { @@ -300,9 +300,9 @@ func TestLeaseGrantErrConnClosed(t *testing.T) { defer close(donec) _, err := cli.Grant(context.TODO(), 5) if !clientv3.IsConnCanceled(err) { - // grpc.ErrClientConnClosing if grpc-go balancer calls 'Get' after client.Close. + // codes.Canceled if grpc-go balancer calls 'Get' after client.Close. // context.Canceled if grpc-go balancer calls 'Get' with an inflight client.Close. - t.Fatalf("expected %v, %v or server unavailable, got %v", err != context.Canceled, grpc.ErrClientConnClosing, err) + t.Errorf("expected %v, %v or server unavailable, got %v", err != context.Canceled, codes.Canceled, err) } }() @@ -372,7 +372,7 @@ func TestLeaseGrantNewAfterClose(t *testing.T) { go func() { _, err := cli.Grant(context.TODO(), 5) if !clientv3.IsConnCanceled(err) { - t.Fatalf("expected %v, %v or server unavailable, got %v", err != context.Canceled, grpc.ErrClientConnClosing, err) + t.Errorf("expected %v, %v or server unavailable, got %v", err != context.Canceled, codes.Canceled, err) } close(donec) }() @@ -405,7 +405,7 @@ func TestLeaseRevokeNewAfterClose(t *testing.T) { go func() { _, err := cli.Revoke(context.TODO(), leaseID) if !clientv3.IsConnCanceled(err) { - t.Fatalf("expected %v, %v or server unavailable, got %v", err != context.Canceled, grpc.ErrClientConnClosing, err) + t.Fatalf("expected %v, %v or server unavailable, got %v", err != context.Canceled, codes.Canceled, err) } close(donec) }() @@ -767,7 +767,7 @@ func TestV3LeaseFailureOverlap(t *testing.T) { if err == nil || err == rpctypes.ErrTimeoutDueToConnectionLost { return } - t.Fatal(err) + t.Error(err) }() } } diff --git a/clientv3/integration/leasing_test.go b/clientv3/integration/leasing_test.go index affb6642a21..db4c512e643 100644 --- a/clientv3/integration/leasing_test.go +++ b/clientv3/integration/leasing_test.go @@ -114,7 +114,7 @@ func TestLeasingInterval(t *testing.T) { } // load into cache - if resp, err = lkv.Get(context.TODO(), "abc/a"); err != nil { + if _, err = lkv.Get(context.TODO(), "abc/a"); err != nil { t.Fatal(err) } @@ -389,7 +389,7 @@ func TestLeasingConcurrentPut(t *testing.T) { go func() { resp, perr := lkv.Put(context.TODO(), "k", "abc") if perr != nil { - t.Fatal(perr) + t.Error(perr) } putc <- resp }() @@ -559,7 +559,7 @@ func TestLeasingOwnerPutResponse(t *testing.T) { if _, err = clus.Client(0).Put(context.TODO(), "k", "abc"); err != nil { t.Fatal(err) } - gresp, gerr := lkv.Get(context.TODO(), "k") + _, gerr := lkv.Get(context.TODO(), "k") if gerr != nil { t.Fatal(gerr) } @@ -573,7 +573,7 @@ func TestLeasingOwnerPutResponse(t *testing.T) { clus.Members[0].Stop(t) - gresp, gerr = lkv.Get(context.TODO(), "k") + gresp, gerr := lkv.Get(context.TODO(), "k") if gerr != nil { t.Fatal(gerr) } @@ -992,7 +992,7 @@ func TestLeasingTxnRandIfThenOrElse(t *testing.T) { for i := 0; i < keyCount/2; i++ { k := fmt.Sprintf("k-%d", rand.Intn(keyCount)) if _, err := kv.Get(context.TODO(), k); err != nil { - t.Fatal(err) + t.Error(err) } getc <- struct{}{} } @@ -1399,10 +1399,10 @@ func TestLeasingReconnectOwnerRevoke(t *testing.T) { // blocks until lkv1 connection comes back resp, err := lkv1.Get(cctx, "k") if err != nil { - t.Fatal(err) + t.Error(err) } if string(resp.Kvs[0].Value) != "v" { - t.Fatalf(`expected "v" value, got %+v`, resp) + t.Errorf(`expected "v" value, got %+v`, resp) } }() select { @@ -1440,11 +1440,11 @@ func TestLeasingReconnectOwnerRevokeCompact(t *testing.T) { clus.WaitLeader(t) // put some more revisions for compaction - presp, err := clus.Client(1).Put(context.TODO(), "a", "123") + _, err := clus.Client(1).Put(context.TODO(), "a", "123") if err != nil { t.Fatal(err) } - presp, err = clus.Client(1).Put(context.TODO(), "a", "123") + presp, err := clus.Client(1).Put(context.TODO(), "a", "123") if err != nil { t.Fatal(err) } @@ -1595,7 +1595,7 @@ func TestLeasingTxnAtomicCache(t *testing.T) { } tresp, err := lkv.Txn(context.TODO()).Then(gets...).Commit() if err != nil { - t.Fatal(err) + t.Error(err) } revs := make([]int64, len(gets)) for i, resp := range tresp.Responses { @@ -1604,7 +1604,7 @@ func TestLeasingTxnAtomicCache(t *testing.T) { } for i := 1; i < len(revs); i++ { if revs[i] != revs[i-1] { - t.Fatalf("expected matching revisions, got %+v", revs) + t.Errorf("expected matching revisions, got %+v", revs) } } } diff --git a/clientv3/integration/metrics_test.go b/clientv3/integration/metrics_test.go index 1b73af9d78d..ba02e351429 100644 --- a/clientv3/integration/metrics_test.go +++ b/clientv3/integration/metrics_test.go @@ -54,12 +54,12 @@ func TestV3ClientMetrics(t *testing.T) { ln, err = transport.NewUnixListener(addr) if err != nil { - t.Fatalf("Error: %v occurred while listening on addr: %v", err, addr) + t.Errorf("Error: %v occurred while listening on addr: %v", err, addr) } err = srv.Serve(ln) if err != nil && !transport.IsClosedConnError(err) { - t.Fatalf("Err serving http requests: %v", err) + t.Errorf("Err serving http requests: %v", err) } }() diff --git a/clientv3/integration/mirror_test.go b/clientv3/integration/mirror_test.go index 46b312ff9f5..a82678e3632 100644 --- a/clientv3/integration/mirror_test.go +++ b/clientv3/integration/mirror_test.go @@ -90,7 +90,7 @@ func TestMirrorSyncBase(t *testing.T) { for key := range keyCh { if _, err := cli.Put(ctx, key, "test"); err != nil { - t.Fatal(err) + t.Error(err) } } }() diff --git a/clientv3/integration/server_shutdown_test.go b/clientv3/integration/server_shutdown_test.go index f7ce58c3672..e7cfeae9d33 100644 --- a/clientv3/integration/server_shutdown_test.go +++ b/clientv3/integration/server_shutdown_test.go @@ -75,16 +75,16 @@ func TestBalancerUnderServerShutdownWatch(t *testing.T) { select { case ev := <-wch: if werr := ev.Err(); werr != nil { - t.Fatal(werr) + t.Error(werr) } if len(ev.Events) != 1 { - t.Fatalf("expected one event, got %+v", ev) + t.Errorf("expected one event, got %+v", ev) } if !bytes.Equal(ev.Events[0].Kv.Value, []byte(val)) { - t.Fatalf("expected %q, got %+v", val, ev.Events[0].Kv) + t.Errorf("expected %q, got %+v", val, ev.Events[0].Kv) } case <-time.After(7 * time.Second): - t.Fatal("took too long to receive events") + t.Error("took too long to receive events") } }() @@ -350,7 +350,7 @@ func testBalancerUnderServerStopInflightRangeOnRestart(t *testing.T, linearizabl } cancel() if err != nil { - t.Fatalf("unexpected error: %v", err) + t.Errorf("unexpected error: %v", err) } }() diff --git a/clientv3/integration/txn_test.go b/clientv3/integration/txn_test.go index af994adbe95..212ecdc3357 100644 --- a/clientv3/integration/txn_test.go +++ b/clientv3/integration/txn_test.go @@ -67,7 +67,7 @@ func TestTxnWriteFail(t *testing.T) { defer cancel() resp, err := kv.Txn(ctx).Then(clientv3.OpPut("foo", "bar")).Commit() if err == nil { - t.Fatalf("expected error, got response %v", resp) + t.Errorf("expected error, got response %v", resp) } close(txnc) }() @@ -76,16 +76,16 @@ func TestTxnWriteFail(t *testing.T) { defer close(getc) select { case <-time.After(5 * time.Second): - t.Fatalf("timed out waiting for txn fail") + t.Errorf("timed out waiting for txn fail") case <-txnc: } // and ensure the put didn't take gresp, gerr := clus.Client(1).Get(context.TODO(), "foo") if gerr != nil { - t.Fatal(gerr) + t.Error(gerr) } if len(gresp.Kvs) != 0 { - t.Fatalf("expected no keys, got %v", gresp.Kvs) + t.Errorf("expected no keys, got %v", gresp.Kvs) } }() @@ -123,7 +123,7 @@ func TestTxnReadRetry(t *testing.T) { go func() { _, err := kv.Txn(context.TODO()).Then(thenOps[i]...).Commit() if err != nil { - t.Fatalf("expected response, got error %v", err) + t.Errorf("expected response, got error %v", err) } donec <- struct{}{} }() diff --git a/clientv3/integration/watch_test.go b/clientv3/integration/watch_test.go index 3482f31bdf0..8f9db99ec26 100644 --- a/clientv3/integration/watch_test.go +++ b/clientv3/integration/watch_test.go @@ -80,13 +80,13 @@ func testWatchMultiWatcher(t *testing.T, wctx *watchctx) { go func(key string) { ch := wctx.w.Watch(context.TODO(), key) if ch == nil { - t.Fatalf("expected watcher channel, got nil") + t.Errorf("expected watcher channel, got nil") } readyc <- struct{}{} for i := 0; i < numKeyUpdates; i++ { resp, ok := <-ch if !ok { - t.Fatalf("watcher unexpectedly closed") + t.Errorf("watcher unexpectedly closed") } v := fmt.Sprintf("%s-%d", key, i) gotv := string(resp.Events[0].Kv.Value) @@ -101,14 +101,14 @@ func testWatchMultiWatcher(t *testing.T, wctx *watchctx) { go func() { prefixc := wctx.w.Watch(context.TODO(), "b", clientv3.WithPrefix()) if prefixc == nil { - t.Fatalf("expected watcher channel, got nil") + t.Errorf("expected watcher channel, got nil") } readyc <- struct{}{} evs := []*clientv3.Event{} for i := 0; i < numKeyUpdates*2; i++ { resp, ok := <-prefixc if !ok { - t.Fatalf("watcher unexpectedly closed") + t.Errorf("watcher unexpectedly closed") } evs = append(evs, resp.Events...) } @@ -134,9 +134,9 @@ func testWatchMultiWatcher(t *testing.T, wctx *watchctx) { select { case resp, ok := <-prefixc: if !ok { - t.Fatalf("watcher unexpectedly closed") + t.Errorf("watcher unexpectedly closed") } - t.Fatalf("unexpected event %+v", resp) + t.Errorf("unexpected event %+v", resp) case <-time.After(time.Second): } donec <- struct{}{} @@ -740,7 +740,7 @@ func TestWatchErrConnClosed(t *testing.T) { ch := cli.Watch(context.TODO(), "foo") if wr := <-ch; !isCanceled(wr.Err()) { - t.Fatalf("expected context canceled, got %v", wr.Err()) + t.Errorf("expected context canceled, got %v", wr.Err()) } }() @@ -772,7 +772,7 @@ func TestWatchAfterClose(t *testing.T) { go func() { cli.Watch(context.TODO(), "foo") if err := cli.Close(); err != nil && err != context.Canceled { - t.Fatalf("expected %v, got %v", context.Canceled, err) + t.Errorf("expected %v, got %v", context.Canceled, err) } close(donec) }() @@ -1036,7 +1036,7 @@ func testWatchOverlapContextCancel(t *testing.T, f func(*integration.ClusterV3)) select { case _, ok := <-wch: if !ok { - t.Fatalf("unexpected closed channel %p", wch) + t.Errorf("unexpected closed channel %p", wch) } // may take a second or two to reestablish a watcher because of // grpc back off policies for disconnects @@ -1078,10 +1078,10 @@ func TestWatchCancelAndCloseClient(t *testing.T) { select { case wr, ok := <-wch: if ok { - t.Fatalf("expected closed watch after cancel(), got resp=%+v err=%v", wr, wr.Err()) + t.Errorf("expected closed watch after cancel(), got resp=%+v err=%v", wr, wr.Err()) } case <-time.After(5 * time.Second): - t.Fatal("timed out waiting for closed channel") + t.Error("timed out waiting for closed channel") } }() cancel() diff --git a/clientv3/leasing/cache.go b/clientv3/leasing/cache.go index f4870c1fb2f..26f8a057873 100644 --- a/clientv3/leasing/cache.go +++ b/clientv3/leasing/cache.go @@ -256,7 +256,7 @@ func (lc *leaseCache) clearOldRevokes(ctx context.Context) { case <-time.After(time.Second): lc.mu.Lock() for k, lr := range lc.revokes { - if time.Now().Sub(lr.Add(revokeBackoff)) > 0 { + if time.Since(lr.Add(revokeBackoff)) > 0 { delete(lc.revokes, k) } } diff --git a/clientv3/op.go b/clientv3/op.go index a3e7d3e77b1..887ac2de533 100644 --- a/clientv3/op.go +++ b/clientv3/op.go @@ -113,13 +113,13 @@ func (op Op) IsGet() bool { return op.t == tRange } func (op Op) IsDelete() bool { return op.t == tDeleteRange } // IsSerializable returns true if the serializable field is true. -func (op Op) IsSerializable() bool { return op.serializable == true } +func (op Op) IsSerializable() bool { return op.serializable } // IsKeysOnly returns whether keysOnly is set. -func (op Op) IsKeysOnly() bool { return op.keysOnly == true } +func (op Op) IsKeysOnly() bool { return op.keysOnly } // IsCountOnly returns whether countOnly is set. -func (op Op) IsCountOnly() bool { return op.countOnly == true } +func (op Op) IsCountOnly() bool { return op.countOnly } // MinModRev returns the operation's minimum modify revision. func (op Op) MinModRev() int64 { return op.minModRev } diff --git a/clientv3/retry_interceptor.go b/clientv3/retry_interceptor.go index 0f5cab84dbb..490c080c2e1 100644 --- a/clientv3/retry_interceptor.go +++ b/clientv3/retry_interceptor.go @@ -28,6 +28,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" ) // unaryClientInterceptor returns a new retrying unary client interceptor. @@ -95,7 +96,7 @@ func (c *Client) streamClientInterceptor(logger *zap.Logger, optFuncs ...retryOp return streamer(ctx, desc, cc, method, grpcOpts...) } if desc.ClientStreams { - return nil, grpc.Errorf(codes.Unimplemented, "clientv3/retry_interceptor: cannot retry on ClientStreams, set Disable()") + return nil, status.Errorf(codes.Unimplemented, "clientv3/retry_interceptor: cannot retry on ClientStreams, set Disable()") } newStreamer, err := streamer(ctx, desc, cc, method, grpcOpts...) logger.Info("retry stream intercept", zap.Error(err)) @@ -282,11 +283,11 @@ func isContextError(err error) bool { func contextErrToGrpcErr(err error) error { switch err { case context.DeadlineExceeded: - return grpc.Errorf(codes.DeadlineExceeded, err.Error()) + return status.Errorf(codes.DeadlineExceeded, err.Error()) case context.Canceled: - return grpc.Errorf(codes.Canceled, err.Error()) + return status.Errorf(codes.Canceled, err.Error()) default: - return grpc.Errorf(codes.Unknown, err.Error()) + return status.Errorf(codes.Unknown, err.Error()) } } diff --git a/clientv3/snapshot/v3_snapshot_test.go b/clientv3/snapshot/v3_snapshot_test.go index 8d2ee9d6aaa..0a4c3096c3a 100644 --- a/clientv3/snapshot/v3_snapshot_test.go +++ b/clientv3/snapshot/v3_snapshot_test.go @@ -295,7 +295,7 @@ func restoreCluster(t *testing.T, clusterN int, dbPath string) ( go func(idx int) { srv, err := embed.StartEtcd(cfgs[idx]) if err != nil { - t.Fatal(err) + t.Error(err) } <-srv.Server.ReadyNotify() diff --git a/contrib/raftexample/raftexample_test.go b/contrib/raftexample/raftexample_test.go index f452efae8a6..f20010ad5c0 100644 --- a/contrib/raftexample/raftexample_test.go +++ b/contrib/raftexample/raftexample_test.go @@ -112,7 +112,7 @@ func TestProposeOnCommit(t *testing.T) { case pC <- *s: continue case err := <-eC: - t.Fatalf("eC message (%v)", err) + t.Errorf("eC message (%v)", err) } } donec <- struct{}{} diff --git a/etcdserver/server_test.go b/etcdserver/server_test.go index 46a5363f815..b7b3a92ce80 100644 --- a/etcdserver/server_test.go +++ b/etcdserver/server_test.go @@ -973,7 +973,7 @@ func TestSnapshot(t *testing.T) { defer func() { ch <- struct{}{} }() if len(gaction) != 1 { - t.Fatalf("len(action) = %d, want 1", len(gaction)) + t.Errorf("len(action) = %d, want 1", len(gaction)) } if !reflect.DeepEqual(gaction[0], testutil.Action{Name: "SaveSnap"}) { t.Errorf("action = %s, want SaveSnap", gaction[0]) @@ -985,7 +985,7 @@ func TestSnapshot(t *testing.T) { defer func() { ch <- struct{}{} }() if len(gaction) != 2 { - t.Fatalf("len(action) = %d, want 2", len(gaction)) + t.Errorf("len(action) = %d, want 2", len(gaction)) } if !reflect.DeepEqual(gaction[0], testutil.Action{Name: "Clone"}) { t.Errorf("action = %s, want Clone", gaction[0]) @@ -1118,7 +1118,7 @@ func TestTriggerSnap(t *testing.T) { // each operation is recorded as a Save // (SnapshotCount+1) * Puts + SaveSnap = (SnapshotCount+1) * Save + SaveSnap if len(gaction) != wcnt { - t.Fatalf("len(action) = %d, want %d", len(gaction), wcnt) + t.Errorf("len(action) = %d, want %d", len(gaction), wcnt) } if !reflect.DeepEqual(gaction[wcnt-1], testutil.Action{Name: "SaveSnap"}) { t.Errorf("action = %s, want SaveSnap", gaction[wcnt-1]) diff --git a/functional/tester/cluster_read_config.go b/functional/tester/cluster_read_config.go index 4ce9d076e67..df0dc667a10 100644 --- a/functional/tester/cluster_read_config.go +++ b/functional/tester/cluster_read_config.go @@ -53,7 +53,7 @@ func read(lg *zap.Logger, fpath string) (*Cluster, error) { } if len(clus.Tester.Cases) == 0 { - return nil, errors.New("Cases not found") + return nil, errors.New("cases not found") } if clus.Tester.DelayLatencyMs <= clus.Tester.DelayLatencyMsRv*5 { return nil, fmt.Errorf("delay latency %d ms must be greater than 5x of delay latency random variable %d ms", clus.Tester.DelayLatencyMs, clus.Tester.DelayLatencyMsRv) @@ -227,7 +227,7 @@ func read(lg *zap.Logger, fpath string) (*Cluster, error) { return nil, fmt.Errorf("Etcd.PeerClientCertAuth and Etcd.PeerAutoTLS cannot be both 'true'") } if (mem.Etcd.PeerCertFile == "") != (mem.Etcd.PeerKeyFile == "") { - return nil, fmt.Errorf("Both Etcd.PeerCertFile %q and Etcd.PeerKeyFile %q must be either empty or non-empty", mem.Etcd.PeerCertFile, mem.Etcd.PeerKeyFile) + return nil, fmt.Errorf("both Etcd.PeerCertFile %q and Etcd.PeerKeyFile %q must be either empty or non-empty", mem.Etcd.PeerCertFile, mem.Etcd.PeerKeyFile) } if mem.Etcd.ClientCertAuth && mem.Etcd.ClientAutoTLS { return nil, fmt.Errorf("Etcd.ClientCertAuth and Etcd.ClientAutoTLS cannot be both 'true'") @@ -251,7 +251,7 @@ func read(lg *zap.Logger, fpath string) (*Cluster, error) { return nil, fmt.Errorf("Etcd.ClientCertAuth 'false', but Etcd.ClientTrustedCAFile is %q", mem.Etcd.PeerCertFile) } if (mem.Etcd.ClientCertFile == "") != (mem.Etcd.ClientKeyFile == "") { - return nil, fmt.Errorf("Both Etcd.ClientCertFile %q and Etcd.ClientKeyFile %q must be either empty or non-empty", mem.Etcd.ClientCertFile, mem.Etcd.ClientKeyFile) + return nil, fmt.Errorf("both Etcd.ClientCertFile %q and Etcd.ClientKeyFile %q must be either empty or non-empty", mem.Etcd.ClientCertFile, mem.Etcd.ClientKeyFile) } peerTLS := mem.Etcd.PeerAutoTLS || diff --git a/functional/tester/stresser_key.go b/functional/tester/stresser_key.go index 7feec463732..c31b5b21175 100644 --- a/functional/tester/stresser_key.go +++ b/functional/tester/stresser_key.go @@ -176,9 +176,6 @@ func (s *keyStresser) isRetryableError(err error) bool { case context.Canceled.Error(): // from stresser.Cancel method: return false - case grpc.ErrClientConnClosing.Error(): - // from stresser.Cancel method: - return false } if status.Convert(err).Code() == codes.Unavailable { diff --git a/integration/v2_http_kv_test.go b/integration/v2_http_kv_test.go index c42e5a87395..62ee92bfc46 100644 --- a/integration/v2_http_kv_test.go +++ b/integration/v2_http_kv_test.go @@ -891,7 +891,7 @@ func TestV2WatchWithIndex(t *testing.T) { go func() { resp, err := tc.Get(fmt.Sprintf("%s%s", u, "/v2/keys/foo/bar?wait=true&waitIndex=5")) if err != nil { - t.Fatalf("watch err = %v, want nil", err) + t.Errorf("watch err = %v, want nil", err) } body = tc.ReadBodyJSON(resp) c <- true @@ -979,7 +979,7 @@ func TestV2WatchKeyInDir(t *testing.T) { // Expect a notification when watching the node resp, err := tc.Get(fmt.Sprintf("%s%s", u, "/v2/keys/keyindir/bar?wait=true")) if err != nil { - t.Fatalf("watch err = %v, want nil", err) + t.Errorf("watch err = %v, want nil", err) } body = tc.ReadBodyJSON(resp) c <- true diff --git a/integration/v3_alarm_test.go b/integration/v3_alarm_test.go index 0763c9b0262..06459718168 100644 --- a/integration/v3_alarm_test.go +++ b/integration/v3_alarm_test.go @@ -159,7 +159,7 @@ func TestV3CorruptAlarm(t *testing.T) { go func() { defer wg.Done() if _, err := clus.Client(0).Put(context.TODO(), "k", "v"); err != nil { - t.Fatal(err) + t.Error(err) } }() } diff --git a/integration/v3_barrier_test.go b/integration/v3_barrier_test.go index 54fa3be665e..1fbc78b3c6a 100644 --- a/integration/v3_barrier_test.go +++ b/integration/v3_barrier_test.go @@ -51,7 +51,7 @@ func testBarrier(t *testing.T, waiters int, chooseClient func() *clientv3.Client go func() { br := recipe.NewBarrier(chooseClient(), "test-barrier") if err := br.Wait(); err != nil { - t.Fatalf("could not wait on barrier (%v)", err) + t.Errorf("could not wait on barrier (%v)", err) } donec <- struct{}{} }() diff --git a/integration/v3_double_barrier_test.go b/integration/v3_double_barrier_test.go index dc5acd84ca4..c4bf4ac684e 100644 --- a/integration/v3_double_barrier_test.go +++ b/integration/v3_double_barrier_test.go @@ -45,11 +45,11 @@ func TestDoubleBarrier(t *testing.T) { bb := recipe.NewDoubleBarrier(session, "test-barrier", waiters) if err := bb.Enter(); err != nil { - t.Fatalf("could not enter on barrier (%v)", err) + t.Errorf("could not enter on barrier (%v)", err) } donec <- struct{}{} if err := bb.Leave(); err != nil { - t.Fatalf("could not leave on barrier (%v)", err) + t.Errorf("could not leave on barrier (%v)", err) } donec <- struct{}{} }() @@ -115,7 +115,7 @@ func TestDoubleBarrierFailover(t *testing.T) { go func() { b := recipe.NewDoubleBarrier(s0, "test-barrier", waiters) if berr := b.Enter(); berr != nil { - t.Fatalf("could not enter on barrier (%v)", berr) + t.Errorf("could not enter on barrier (%v)", berr) } donec <- struct{}{} }() @@ -124,7 +124,7 @@ func TestDoubleBarrierFailover(t *testing.T) { go func() { b := recipe.NewDoubleBarrier(s1, "test-barrier", waiters) if berr := b.Enter(); berr != nil { - t.Fatalf("could not enter on barrier (%v)", berr) + t.Errorf("could not enter on barrier (%v)", berr) } donec <- struct{}{} b.Leave() diff --git a/integration/v3_election_test.go b/integration/v3_election_test.go index 4598448001b..835d3ebc0a2 100644 --- a/integration/v3_election_test.go +++ b/integration/v3_election_test.go @@ -53,7 +53,7 @@ func TestElectionWait(t *testing.T) { defer cancel() s, ok := <-b.Observe(cctx) if !ok { - t.Fatalf("could not observe election; channel closed") + t.Errorf("could not observe election; channel closed") } electedc <- string(s.Kvs[0].Value) // wait for next election round @@ -76,7 +76,7 @@ func TestElectionWait(t *testing.T) { e := concurrency.NewElection(session, "test-election") ev := fmt.Sprintf("electval-%v", time.Now().UnixNano()) if err := e.Campaign(context.TODO(), ev); err != nil { - t.Fatalf("failed volunteer (%v)", err) + t.Errorf("failed volunteer (%v)", err) } // wait for followers to accept leadership for j := 0; j < followers; j++ { @@ -87,7 +87,7 @@ func TestElectionWait(t *testing.T) { } // let next leader take over if err := e.Resign(context.TODO()); err != nil { - t.Fatalf("failed resign (%v)", err) + t.Errorf("failed resign (%v)", err) } // tell followers to start listening for next leader for j := 0; j < followers; j++ { diff --git a/integration/v3_grpc_inflight_test.go b/integration/v3_grpc_inflight_test.go index 1a0a11a8e1b..c89bc2c4acc 100644 --- a/integration/v3_grpc_inflight_test.go +++ b/integration/v3_grpc_inflight_test.go @@ -86,7 +86,7 @@ func TestV3KVInflightRangeRequests(t *testing.T) { errCode := status.Convert(err).Code() errDesc := rpctypes.ErrorDesc(err) if err != nil && !(errDesc == context.Canceled.Error() || errCode == codes.Unavailable) { - t.Fatalf("inflight request should be canceled with '%v' or code Unavailable, got '%v' with code '%s'", context.Canceled.Error(), errDesc, errCode) + t.Errorf("inflight request should be canceled with '%v' or code Unavailable, got '%v' with code '%s'", context.Canceled.Error(), errDesc, errCode) } } }() diff --git a/integration/v3_lease_test.go b/integration/v3_lease_test.go index 7b378f0c92f..6e20b01f40e 100644 --- a/integration/v3_lease_test.go +++ b/integration/v3_lease_test.go @@ -623,7 +623,7 @@ func TestV3LeaseRequireLeader(t *testing.T) { defer close(donec) resp, err := lac.Recv() if err == nil { - t.Fatalf("got response %+v, expected error", resp) + t.Errorf("got response %+v, expected error", resp) } if rpctypes.ErrorDesc(err) != rpctypes.ErrNoLeader.Error() { t.Errorf("err = %v, want %v", err, rpctypes.ErrNoLeader) diff --git a/integration/v3_lock_test.go b/integration/v3_lock_test.go index 10b501eafab..88e032796cd 100644 --- a/integration/v3_lock_test.go +++ b/integration/v3_lock_test.go @@ -57,7 +57,7 @@ func testMutex(t *testing.T, waiters int, chooseClient func() *clientv3.Client) } m := concurrency.NewMutex(session, "test-mutex") if err := m.Lock(context.TODO()); err != nil { - t.Fatalf("could not wait on lock (%v)", err) + t.Errorf("could not wait on lock (%v)", err) } lockedC <- m }() @@ -248,12 +248,12 @@ func testRWMutex(t *testing.T, waiters int, chooseClient func() *clientv3.Client rwm := recipe.NewRWMutex(session, "test-rwmutex") if rand.Intn(2) == 0 { if err := rwm.RLock(); err != nil { - t.Fatalf("could not rlock (%v)", err) + t.Errorf("could not rlock (%v)", err) } rlockedC <- rwm } else { if err := rwm.Lock(); err != nil { - t.Fatalf("could not lock (%v)", err) + t.Errorf("could not lock (%v)", err) } wlockedC <- rwm } diff --git a/integration/v3_queue_test.go b/integration/v3_queue_test.go index c7349fd8410..d64571996ad 100644 --- a/integration/v3_queue_test.go +++ b/integration/v3_queue_test.go @@ -42,7 +42,7 @@ func TestQueueOneReaderOneWriter(t *testing.T) { q := recipe.NewQueue(etcdc, "testq") for i := 0; i < 5; i++ { if err := q.Enqueue(fmt.Sprintf("%d", i)); err != nil { - t.Fatalf("error enqueuing (%v)", err) + t.Errorf("error enqueuing (%v)", err) } } }() diff --git a/integration/v3_stm_test.go b/integration/v3_stm_test.go index 25a1fd6c6d3..4ef82bacf7f 100644 --- a/integration/v3_stm_test.go +++ b/integration/v3_stm_test.go @@ -170,7 +170,7 @@ func TestSTMSerialize(t *testing.T) { ops = append(ops, v3.OpPut(k, s)) } if _, err := etcdc.Txn(context.TODO()).Then(ops...).Commit(); err != nil { - t.Fatalf("couldn't put keys (%v)", err) + t.Errorf("couldn't put keys (%v)", err) } updatec <- struct{}{} } @@ -220,7 +220,7 @@ func TestSTMApplyOnConcurrentDeletion(t *testing.T) { go func() { <-readyc if _, err := etcdc.Delete(context.TODO(), "foo"); err != nil { - t.Fatal(err) + t.Error(err) } close(donec) }() diff --git a/integration/v3_watch_test.go b/integration/v3_watch_test.go index da255d569e5..2de2db4c411 100644 --- a/integration/v3_watch_test.go +++ b/integration/v3_watch_test.go @@ -250,7 +250,7 @@ func TestV3WatchFromCurrentRevision(t *testing.T) { kvc := toGRPC(clus.RandClient()).KV req := &pb.PutRequest{Key: []byte(k), Value: []byte("bar")} if _, err := kvc.Put(context.TODO(), req); err != nil { - t.Fatalf("#%d: couldn't put key (%v)", i, err) + t.Errorf("#%d: couldn't put key (%v)", i, err) } } }() @@ -484,7 +484,7 @@ func TestV3WatchCurrentPutOverlap(t *testing.T) { kvc := toGRPC(clus.RandClient()).KV req := &pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")} if _, err := kvc.Put(context.TODO(), req); err != nil { - t.Fatalf("couldn't put key (%v)", err) + t.Errorf("couldn't put key (%v)", err) } }() } @@ -927,7 +927,7 @@ func testV3WatchMultipleStreams(t *testing.T, startRev int64) { wStream := streams[i] wresp, err := wStream.Recv() if err != nil { - t.Fatalf("wStream.Recv error: %v", err) + t.Errorf("wStream.Recv error: %v", err) } if wresp.WatchId != 0 { t.Errorf("watchId got = %d, want = 0", wresp.WatchId) @@ -1090,7 +1090,7 @@ func TestV3WatchWithFilter(t *testing.T) { // check received PUT resp, rerr := ws.Recv() if rerr != nil { - t.Fatal(rerr) + t.Error(rerr) } recv <- resp }() @@ -1183,7 +1183,7 @@ func TestV3WatchWithPrevKV(t *testing.T) { // check received PUT resp, rerr := ws.Recv() if rerr != nil { - t.Fatal(rerr) + t.Error(rerr) } recv <- resp }() diff --git a/integration/v3election_grpc_test.go b/integration/v3election_grpc_test.go index d49ad24fcb4..664b4f3139d 100644 --- a/integration/v3election_grpc_test.go +++ b/integration/v3election_grpc_test.go @@ -54,10 +54,10 @@ func TestV3ElectionCampaign(t *testing.T) { req2 := &epb.CampaignRequest{Name: []byte("foo"), Lease: lease2.ID, Value: []byte("def")} l2, lerr2 := lc.Campaign(context.TODO(), req2) if lerr2 != nil { - t.Fatal(lerr2) + t.Error(lerr2) } if l1.Header.Revision >= l2.Header.Revision { - t.Fatalf("expected l1 revision < l2 revision, got %d >= %d", l1.Header.Revision, l2.Header.Revision) + t.Errorf("expected l1 revision < l2 revision, got %d >= %d", l1.Header.Revision, l2.Header.Revision) } }() @@ -103,18 +103,18 @@ func TestV3ElectionObserve(t *testing.T) { s, err := lc.Observe(context.Background(), &epb.LeaderRequest{Name: []byte("foo")}) observec <- struct{}{} if err != nil { - t.Fatal(err) + t.Error(err) } for i := 0; i < 10; i++ { resp, rerr := s.Recv() if rerr != nil { - t.Fatal(rerr) + t.Error(rerr) } respV := 0 fmt.Sscanf(string(resp.Kv.Value), "%d", &respV) // leader transitions should not go backwards if respV < i { - t.Fatalf(`got observe value %q, expected >= "%d"`, string(resp.Kv.Value), i) + t.Errorf(`got observe value %q, expected >= "%d"`, string(resp.Kv.Value), i) } i = respV } @@ -142,17 +142,17 @@ func TestV3ElectionObserve(t *testing.T) { lease2, err2 := toGRPC(clus.RandClient()).Lease.LeaseGrant(context.TODO(), &pb.LeaseGrantRequest{TTL: 30}) if err2 != nil { - t.Fatal(err2) + t.Error(err2) } c2, cerr2 := lc.Campaign(context.TODO(), &epb.CampaignRequest{Name: []byte("foo"), Lease: lease2.ID, Value: []byte("5")}) if cerr2 != nil { - t.Fatal(cerr2) + t.Error(cerr2) } for i := 6; i < 10; i++ { v := []byte(fmt.Sprintf("%d", i)) req := &epb.ProclaimRequest{Leader: c2.Leader, Value: v} if _, err := lc.Proclaim(context.TODO(), req); err != nil { - t.Fatal(err) + t.Error(err) } } }() diff --git a/integration/v3lock_grpc_test.go b/integration/v3lock_grpc_test.go index 05276669f3a..0888704bc9c 100644 --- a/integration/v3lock_grpc_test.go +++ b/integration/v3lock_grpc_test.go @@ -50,10 +50,10 @@ func TestV3LockLockWaiter(t *testing.T) { go func() { l2, lerr2 := lc.Lock(context.TODO(), &lockpb.LockRequest{Name: []byte("foo"), Lease: lease2.ID}) if lerr2 != nil { - t.Fatal(lerr2) + t.Error(lerr2) } if l1.Header.Revision >= l2.Header.Revision { - t.Fatalf("expected l1 revision < l2 revision, got %d >= %d", l1.Header.Revision, l2.Header.Revision) + t.Errorf("expected l1 revision < l2 revision, got %d >= %d", l1.Header.Revision, l2.Header.Revision) } close(lockc) }() diff --git a/lease/lessor_test.go b/lease/lessor_test.go index 7f2d8f68bb6..6b199cbb566 100644 --- a/lease/lessor_test.go +++ b/lease/lessor_test.go @@ -389,7 +389,7 @@ func TestLessorExpire(t *testing.T) { go func() { // expired lease cannot be renewed if _, err := le.Renew(l.ID); err != ErrLeaseNotFound { - t.Fatalf("unexpected renew") + t.Errorf("unexpected renew") } donec <- struct{}{} }() @@ -442,7 +442,7 @@ func TestLessorExpireAndDemote(t *testing.T) { go func() { // expired lease cannot be renewed if _, err := le.Renew(l.ID); err != ErrNotPrimary { - t.Fatalf("unexpected renew: %v", err) + t.Errorf("unexpected renew: %v", err) } donec <- struct{}{} }() diff --git a/mvcc/kvstore_test.go b/mvcc/kvstore_test.go index ef48464d6f9..db6933e7e20 100644 --- a/mvcc/kvstore_test.go +++ b/mvcc/kvstore_test.go @@ -550,7 +550,7 @@ func TestHashKVWhenCompacting(t *testing.T) { for { hash, _, compactRev, err := s.HashByRev(int64(rev)) if err != nil { - t.Fatal(err) + t.Error(err) } select { case <-donec: @@ -570,7 +570,7 @@ func TestHashKVWhenCompacting(t *testing.T) { revHash[r.compactRev] = r.hash } if r.hash != revHash[r.compactRev] { - t.Fatalf("Hashes differ (current %v) != (saved %v)", r.hash, revHash[r.compactRev]) + t.Errorf("Hashes differ (current %v) != (saved %v)", r.hash, revHash[r.compactRev]) } } }() @@ -581,7 +581,7 @@ func TestHashKVWhenCompacting(t *testing.T) { for i := 100; i >= 0; i-- { _, err := s.Compact(int64(rev - 1 - i)) if err != nil { - t.Fatal(err) + t.Error(err) } time.Sleep(10 * time.Millisecond) } diff --git a/pkg/expect/expect_test.go b/pkg/expect/expect_test.go index d5cdaef5893..c5ed18ec60b 100644 --- a/pkg/expect/expect_test.go +++ b/pkg/expect/expect_test.go @@ -109,7 +109,7 @@ func TestSignal(t *testing.T) { defer close(donec) werr := "signal: interrupt" if cerr := ep.Close(); cerr == nil || cerr.Error() != werr { - t.Fatalf("got error %v, wanted error %s", cerr, werr) + t.Errorf("got error %v, wanted error %s", cerr, werr) } }() select { diff --git a/pkg/fileutil/lock_test.go b/pkg/fileutil/lock_test.go index 7c1dd864414..ded6051dccb 100644 --- a/pkg/fileutil/lock_test.go +++ b/pkg/fileutil/lock_test.go @@ -61,11 +61,11 @@ func TestLockAndUnlock(t *testing.T) { go func() { bl, blerr := LockFile(f.Name(), os.O_WRONLY, PrivateFileMode) if blerr != nil { - t.Fatal(blerr) + t.Error(blerr) } locked <- struct{}{} if blerr = bl.Close(); blerr != nil { - t.Fatal(blerr) + t.Error(blerr) } }() diff --git a/pkg/fileutil/purge_test.go b/pkg/fileutil/purge_test.go index fe313e50f13..908e5f8db2a 100644 --- a/pkg/fileutil/purge_test.go +++ b/pkg/fileutil/purge_test.go @@ -57,7 +57,7 @@ func TestPurgeFile(t *testing.T) { go func(n int) { f, ferr := os.Create(filepath.Join(dir, fmt.Sprintf("%d.test", n))) if ferr != nil { - t.Fatal(err) + t.Error(err) } f.Close() }(i) diff --git a/pkg/transport/timeout_dialer_test.go b/pkg/transport/timeout_dialer_test.go index c082ca374f4..92589cea5ff 100644 --- a/pkg/transport/timeout_dialer_test.go +++ b/pkg/transport/timeout_dialer_test.go @@ -95,7 +95,7 @@ func (ts *testBlockingServer) Start(t *testing.T) { for i := 0; i < ts.n; i++ { conn, err := ts.ln.Accept() if err != nil { - t.Fatal(err) + t.Error(err) } defer conn.Close() } diff --git a/pkg/transport/timeout_listener_test.go b/pkg/transport/timeout_listener_test.go index be2495d47b2..fe09fe31e1a 100644 --- a/pkg/transport/timeout_listener_test.go +++ b/pkg/transport/timeout_listener_test.go @@ -52,7 +52,7 @@ func TestWriteReadTimeoutListener(t *testing.T) { blocker := func() { conn, derr := net.Dial("tcp", ln.Addr().String()) if derr != nil { - t.Fatalf("unexpected dail error: %v", derr) + t.Errorf("unexpected dail error: %v", derr) } defer conn.Close() // block the receiver until the writer timeout diff --git a/pkg/transport/transport_test.go b/pkg/transport/transport_test.go index f0860f8e706..44c03a958fb 100644 --- a/pkg/transport/transport_test.go +++ b/pkg/transport/transport_test.go @@ -58,12 +58,12 @@ func TestNewTransportTLSInvalidCipherSuites(t *testing.T) { go func() { tr, err := NewTransport(cliTLS, 3*time.Second) if err != nil { - t.Fatalf("unexpected NewTransport error: %v", err) + t.Errorf("unexpected NewTransport error: %v", err) } cli := &http.Client{Transport: tr} _, gerr := cli.Get("https://" + ln.Addr().String()) if gerr == nil || !strings.Contains(gerr.Error(), "tls: handshake failure") { - t.Fatal("expected client TLS handshake error") + t.Error("expected client TLS handshake error") } ln.Close() donec <- struct{}{} diff --git a/proxy/grpcproxy/adapter/chan_stream.go b/proxy/grpcproxy/adapter/chan_stream.go index 82e34119311..0be39765e7b 100644 --- a/proxy/grpcproxy/adapter/chan_stream.go +++ b/proxy/grpcproxy/adapter/chan_stream.go @@ -120,7 +120,10 @@ func (s *chanStream) RecvMsg(m interface{}) error { select { case msg, ok := <-s.recvc: if !ok { - return grpc.ErrClientConnClosing + if s.ctx.Err() != nil { + err := s.ctx.Err() + return err + } } if err, ok := msg.(error); ok { return err diff --git a/proxy/grpcproxy/lease.go b/proxy/grpcproxy/lease.go index a688d429a20..1110a946a4d 100644 --- a/proxy/grpcproxy/lease.go +++ b/proxy/grpcproxy/lease.go @@ -214,7 +214,7 @@ func (lp *leaseProxy) LeaseKeepAlive(stream pb.Lease_LeaseKeepAliveServer) error case <-lostLeaderC: return rpctypes.ErrNoLeader case <-lp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing + return context.Canceled default: if err != nil { return err diff --git a/proxy/grpcproxy/watch.go b/proxy/grpcproxy/watch.go index 639bf8e2d60..733f6ad81b1 100644 --- a/proxy/grpcproxy/watch.go +++ b/proxy/grpcproxy/watch.go @@ -23,7 +23,6 @@ import ( "go.etcd.io/etcd/etcdserver/api/v3rpc/rpctypes" pb "go.etcd.io/etcd/etcdserver/etcdserverpb" - "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) @@ -80,7 +79,7 @@ func (wp *watchProxy) Watch(stream pb.Watch_WatchServer) (err error) { wp.mu.Unlock() select { case <-wp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing + return context.Canceled default: return wp.ctx.Err() } @@ -153,7 +152,7 @@ func (wp *watchProxy) Watch(stream pb.Watch_WatchServer) (err error) { case <-lostLeaderC: return rpctypes.ErrNoLeader case <-wp.leader.disconnectNotify(): - return grpc.ErrClientConnClosing + return context.Canceled default: return wps.ctx.Err() } diff --git a/tests/e2e/ctl_v3_auth_test.go b/tests/e2e/ctl_v3_auth_test.go index 6dbcd103950..a243278d2be 100644 --- a/tests/e2e/ctl_v3_auth_test.go +++ b/tests/e2e/ctl_v3_auth_test.go @@ -845,7 +845,7 @@ func authTestWatch(cx ctlCtx) { defer close(donec) for j := range puts { if err := ctlV3Put(cx, puts[j].key, puts[j].val, ""); err != nil { - cx.t.Fatalf("watchTest #%d-%d: ctlV3Put error (%v)", i, j, err) + cx.t.Errorf("watchTest #%d-%d: ctlV3Put error (%v)", i, j, err) } } }(i, tt.puts) diff --git a/tests/e2e/ctl_v3_watch_no_cov_test.go b/tests/e2e/ctl_v3_watch_no_cov_test.go index 6dffeee3f14..1778ecd37eb 100644 --- a/tests/e2e/ctl_v3_watch_no_cov_test.go +++ b/tests/e2e/ctl_v3_watch_no_cov_test.go @@ -133,7 +133,7 @@ func watchTest(cx ctlCtx) { go func(i int, puts []kv) { for j := range puts { if err := ctlV3Put(cx, puts[j].key, puts[j].val, ""); err != nil { - cx.t.Fatalf("watchTest #%d-%d: ctlV3Put error (%v)", i, j, err) + cx.t.Errorf("watchTest #%d-%d: ctlV3Put error (%v)", i, j, err) } } close(donec) diff --git a/tests/e2e/etcd_release_upgrade_test.go b/tests/e2e/etcd_release_upgrade_test.go index 6a8e5b13ac6..0ebdbf1e174 100644 --- a/tests/e2e/etcd_release_upgrade_test.go +++ b/tests/e2e/etcd_release_upgrade_test.go @@ -168,7 +168,7 @@ func TestReleaseUpgradeWithRestart(t *testing.T) { epc.procs[i].Config().execPath = binDir + "/etcd" epc.procs[i].Config().keepDataDir = true if err := epc.procs[i].Restart(); err != nil { - t.Fatalf("error restarting etcd process (%v)", err) + t.Errorf("error restarting etcd process (%v)", err) } wg.Done() }(i)