Skip to content

Commit

Permalink
finish inequality conversions
Browse files Browse the repository at this point in the history
Signed-off-by: redwrasse <[email protected]>
  • Loading branch information
redwrasse committed Sep 24, 2024
1 parent 5e63c25 commit e3319c5
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func testBalancerUnderNetworkPartition(t *testing.T, op func(*clientv3.Client, c
if err == nil {
break
}
if err != errExpected {
if !errors.Is(err, errExpected) {
t.Errorf("#%d: expected '%v', got '%v'", i, errExpected, err)
}
// give enough time for endpoint switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package recipes_test

import (
"context"
"errors"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -149,7 +150,7 @@ func TestDoubleBarrierTooManyClients(t *testing.T) {
// no any other client can enter the barrier.
wgEntered.Wait()
t.Log("Try to enter into double barrier")
if err = b.Enter(); err != recipe.ErrTooManyClients {
if err = b.Enter(); !errors.Is(err, recipe.ErrTooManyClients) {
t.Errorf("Unexcepted error, expected: ErrTooManyClients, got: %v", err)
}

Expand Down
7 changes: 4 additions & 3 deletions tests/integration/clientv3/lease/leasing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package lease_test

import (
"context"
"errors"
"fmt"
"math/rand"
"reflect"
Expand Down Expand Up @@ -895,7 +896,7 @@ func TestLeasingTxnCancel(t *testing.T) {
time.Sleep(100 * time.Millisecond)
cancel()
}()
if _, err := lkv2.Txn(ctx).Then(clientv3.OpPut("k", "v")).Commit(); err != context.Canceled {
if _, err := lkv2.Txn(ctx).Then(clientv3.OpPut("k", "v")).Commit(); !errors.Is(err, context.Canceled) {
t.Fatalf("expected %v, got %v", context.Canceled, err)
}
}
Expand Down Expand Up @@ -2017,7 +2018,7 @@ func TestLeasingSessionExpireCancel(t *testing.T) {

select {
case err := <-errc:
if err != ctx.Err() {
if !errors.Is(err, ctx.Err()) {
t.Errorf("#%d: expected %v of server unavailable, got %v", i, ctx.Err(), err)
}
case <-time.After(5 * time.Second):
Expand Down Expand Up @@ -2048,7 +2049,7 @@ func waitForExpireAck(t *testing.T, kv clientv3.KV) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
_, err := kv.Get(ctx, "abc")
cancel()
if err == ctx.Err() {
if errors.Is(err, ctx.Err()) {
return
} else if err != nil {
t.Logf("current error: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/clientv3/maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestMaintenanceSnapshotCancel(t *testing.T) {

cancel()
_, err = io.Copy(io.Discard, rc1)
if err != context.Canceled {
if !errors.Is(err, context.Canceled) {
t.Errorf("expected %v, got %v", context.Canceled, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/clientv3/ordering_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestDetectKvOrderViolation(t *testing.T) {
t.Logf("Quering m2 after restart")
v, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable())
t.Logf("Quering m2 returned: v:%v err:%v ", v, err)
if err != errOrderViolation {
if !errors.Is(err, errOrderViolation) {
t.Fatalf("expected %v, got err:%v v:%v", errOrderViolation, err, v)
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestDetectTxnOrderViolation(t *testing.T) {
cli.SetEndpoints(clus.Members[2].GRPCURL)
time.Sleep(2 * time.Second) // FIXME: Figure out how pause SetEndpoints sufficiently that this is not needed
_, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable())
if err != errOrderViolation {
if !errors.Is(err, errOrderViolation) {
t.Fatalf("expected %v, got %v", errOrderViolation, err)
}
orderingTxn = orderingKv.Txn(ctx)
Expand All @@ -164,7 +164,7 @@ func TestDetectTxnOrderViolation(t *testing.T) {
).Then(
clientv3.OpGet("foo", clientv3.WithSerializable()),
).Commit()
if err != errOrderViolation {
if !errors.Is(err, errOrderViolation) {
t.Fatalf("expected %v, got %v", errOrderViolation, err)
}
}
5 changes: 3 additions & 2 deletions tests/integration/clientv3/ordering_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package clientv3test

import (
"context"
"errors"
"testing"
"time"

Expand Down Expand Up @@ -78,7 +79,7 @@ func TestEndpointSwitchResolvesViolation(t *testing.T) {
cli.SetEndpoints(clus.Members[2].GRPCURL)
time.Sleep(1 * time.Second) // give enough time for the operation
_, err = orderingKv.Get(ctx, "foo", clientv3.WithSerializable())
if err != ordering.ErrNoGreaterRev {
if !errors.Is(err, ordering.ErrNoGreaterRev) {
t.Fatal("While speaking to partitioned leader, we should get ErrNoGreaterRev error")
}

Expand Down Expand Up @@ -156,7 +157,7 @@ func TestUnresolvableOrderViolation(t *testing.T) {
time.Sleep(1 * time.Second) // give enough time for operation

_, err = OrderingKv.Get(ctx, "foo", clientv3.WithSerializable())
if err != ordering.ErrNoGreaterRev {
if !errors.Is(err, ordering.ErrNoGreaterRev) {
t.Fatalf("expected %v, got %v", ordering.ErrNoGreaterRev, err)
}
}
2 changes: 1 addition & 1 deletion tests/integration/clientv3/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestTxnError(t *testing.T) {
ops[i] = clientv3.OpPut(fmt.Sprintf("foo%d", i), "")
}
_, err = kv.Txn(ctx).Then(ops...).Commit()
if err != rpctypes.ErrTooManyOps {
if !errors.Is(err, rpctypes.ErrTooManyOps) {
t.Fatalf("expected %v, got %v", rpctypes.ErrTooManyOps, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/clientv3/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestUserErrorAuth(t *testing.T) {
authSetupRoot(t, authapi.Auth)

// unauthenticated client
if _, err := authapi.UserAdd(context.TODO(), "foo", "bar"); err != rpctypes.ErrUserEmpty {
if _, err := authapi.UserAdd(context.TODO(), "foo", "bar"); !errors.Is(err, rpctypes.ErrUserEmpty) {
t.Fatalf("expected %v, got %v", rpctypes.ErrUserEmpty, err)
}

Expand All @@ -128,11 +128,11 @@ func TestUserErrorAuth(t *testing.T) {
DialOptions: []grpc.DialOption{grpc.WithBlock()},
}
cfg.Username, cfg.Password = "wrong-id", "123"
if _, err := integration2.NewClient(t, cfg); err != rpctypes.ErrAuthFailed {
if _, err := integration2.NewClient(t, cfg); !errors.Is(err, rpctypes.ErrAuthFailed) {
t.Fatalf("expected %v, got %v", rpctypes.ErrAuthFailed, err)
}
cfg.Username, cfg.Password = "root", "wrong-pass"
if _, err := integration2.NewClient(t, cfg); err != rpctypes.ErrAuthFailed {
if _, err := integration2.NewClient(t, cfg); !errors.Is(err, rpctypes.ErrAuthFailed) {
t.Fatalf("expected %v, got %v", rpctypes.ErrAuthFailed, err)
}

Expand Down
5 changes: 3 additions & 2 deletions tests/integration/v3_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package integration
import (
"bytes"
"context"
"errors"
"fmt"
"math/rand"
"os"
Expand Down Expand Up @@ -1599,7 +1600,7 @@ func TestTLSGRPCRejectSecureClient(t *testing.T) {
if client != nil || err == nil {
client.Close()
t.Fatalf("expected no client")
} else if err != context.DeadlineExceeded {
} else if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("unexpected error (%v)", err)
}
}
Expand Down Expand Up @@ -1776,7 +1777,7 @@ func testTLSReload(
// 5. expect dial time-out when loading expired certs
select {
case gerr := <-errc:
if gerr != context.DeadlineExceeded {
if !errors.Is(gerr, context.DeadlineExceeded) {
t.Fatalf("expected %v, got %v", context.DeadlineExceeded, gerr)
}
case <-time.After(5 * time.Second):
Expand Down

0 comments on commit e3319c5

Please sign in to comment.