server: address Go 1.24 usetesting issues
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
05d57531e4
commit
dc6db52c34
@ -15,7 +15,6 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"maps"
|
||||
"testing"
|
||||
@ -96,7 +95,7 @@ func testJWTInfo(t *testing.T, opts map[string]string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
ctx := t.Context()
|
||||
|
||||
token, aerr := jwt.assign(ctx, "abc", 123)
|
||||
if aerr != nil {
|
||||
@ -196,7 +195,7 @@ func TestJWTTokenWithMissingFields(t *testing.T) {
|
||||
// verify the token
|
||||
jwtProvider, err := newTokenProviderJWT(zap.NewNop(), optsMap)
|
||||
require.NoError(t, err)
|
||||
ai, ok := jwtProvider.info(context.TODO(), token, 123)
|
||||
ai, ok := jwtProvider.info(t.Context(), token, 123)
|
||||
|
||||
require.Equal(t, tc.expectValid, ok)
|
||||
if ok {
|
||||
|
@ -31,7 +31,7 @@ func TestSimpleTokenDisabled(t *testing.T) {
|
||||
explicitlyDisabled.disable()
|
||||
|
||||
for _, tp := range []*tokenSimple{initialState, explicitlyDisabled} {
|
||||
ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
token, err := tp.assign(ctx, "user1", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -51,7 +51,7 @@ func TestSimpleTokenAssign(t *testing.T) {
|
||||
tp := newTokenProviderSimple(zaptest.NewLogger(t), dummyIndexWaiter, simpleTokenTTLDefault)
|
||||
tp.enable()
|
||||
defer tp.disable()
|
||||
ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
token, err := tp.assign(ctx, "user1", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -63,7 +63,7 @@ func TestSimpleTokenAssign(t *testing.T) {
|
||||
|
||||
tp.invalidateUser("user1")
|
||||
|
||||
_, ok = tp.info(context.TODO(), token, 0)
|
||||
_, ok = tp.info(t.Context(), token, 0)
|
||||
if ok {
|
||||
t.Errorf("expected ok == false after user is invalidated")
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ func TestUserChangePassword(t *testing.T) {
|
||||
as, tearDown := setupAuthStore(t)
|
||||
defer tearDown(t)
|
||||
|
||||
ctx1 := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx1 := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, err := as.Authenticate(ctx1, "foo", "bar")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -291,7 +291,7 @@ func TestUserChangePassword(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx2 := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx2 := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, err = as.Authenticate(ctx2, "foo", "baz")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -811,38 +811,38 @@ func TestAuthInfoFromCtx(t *testing.T) {
|
||||
as, tearDown := setupAuthStore(t)
|
||||
defer tearDown(t)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
ai, err := as.AuthInfoFromCtx(ctx)
|
||||
if err != nil && ai != nil {
|
||||
t.Errorf("expected (nil, nil), got (%v, %v)", ai, err)
|
||||
}
|
||||
|
||||
// as if it came from RPC
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{"tokens": "dummy"}))
|
||||
ctx = metadata.NewIncomingContext(t.Context(), metadata.New(map[string]string{"tokens": "dummy"}))
|
||||
ai, err = as.AuthInfoFromCtx(ctx)
|
||||
if err != nil && ai != nil {
|
||||
t.Errorf("expected (nil, nil), got (%v, %v)", ai, err)
|
||||
}
|
||||
|
||||
ctx = context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx = context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
resp, err := as.Authenticate(ctx, "foo", "bar")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "Invalid Token"}))
|
||||
ctx = metadata.NewIncomingContext(t.Context(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "Invalid Token"}))
|
||||
_, err = as.AuthInfoFromCtx(ctx)
|
||||
if !errors.Is(err, ErrInvalidAuthToken) {
|
||||
t.Errorf("expected %v, got %v", ErrInvalidAuthToken, err)
|
||||
}
|
||||
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "Invalid.Token"}))
|
||||
ctx = metadata.NewIncomingContext(t.Context(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "Invalid.Token"}))
|
||||
_, err = as.AuthInfoFromCtx(ctx)
|
||||
if !errors.Is(err, ErrInvalidAuthToken) {
|
||||
t.Errorf("expected %v, got %v", ErrInvalidAuthToken, err)
|
||||
}
|
||||
|
||||
ctx = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: resp.Token}))
|
||||
ctx = metadata.NewIncomingContext(t.Context(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: resp.Token}))
|
||||
ai, err = as.AuthInfoFromCtx(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@ -857,7 +857,7 @@ func TestAuthDisable(t *testing.T) {
|
||||
defer tearDown(t)
|
||||
|
||||
as.AuthDisable()
|
||||
ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, err := as.Authenticate(ctx, "foo", "bar")
|
||||
if !errors.Is(err, ErrAuthNotEnabled) {
|
||||
t.Errorf("expected %v, got %v", ErrAuthNotEnabled, err)
|
||||
@ -879,7 +879,7 @@ func TestIsAuthEnabled(t *testing.T) {
|
||||
as.AuthEnable()
|
||||
|
||||
status := as.IsAuthEnabled()
|
||||
ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, _ = as.Authenticate(ctx, "foo", "bar")
|
||||
if status != true {
|
||||
t.Errorf("expected %v, got %v", true, false)
|
||||
@ -907,7 +907,7 @@ func TestAuthInfoFromCtxRace(t *testing.T) {
|
||||
donec := make(chan struct{})
|
||||
go func() {
|
||||
defer close(donec)
|
||||
ctx := metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "test"}))
|
||||
ctx := metadata.NewIncomingContext(t.Context(), metadata.New(map[string]string{rpctypes.TokenFieldNameGRPC: "test"}))
|
||||
as.AuthInfoFromCtx(ctx)
|
||||
}()
|
||||
as.UserAdd(&pb.AuthUserAddRequest{Name: "test", Options: &authpb.UserAddOptions{NoPassword: false}})
|
||||
@ -1025,7 +1025,7 @@ func TestHammerSimpleAuthenticate(t *testing.T) {
|
||||
go func(user string) {
|
||||
defer wg.Done()
|
||||
token := fmt.Sprintf("%s(%d)", user, i)
|
||||
ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, token)
|
||||
ctx := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, token)
|
||||
if _, err := as.Authenticate(ctx, user, "123"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -1106,7 +1106,7 @@ func testAuthInfoFromCtxWithRoot(t *testing.T, opts string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := t.Context()
|
||||
ctx = as.WithRoot(ctx)
|
||||
|
||||
ai, aerr := as.AuthInfoFromCtx(ctx)
|
||||
@ -1130,7 +1130,7 @@ func TestUserNoPasswordAdd(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, err = as.Authenticate(ctx, username, "")
|
||||
require.ErrorIsf(t, err, ErrAuthFailed, "expected %v, got %v", ErrAuthFailed, err)
|
||||
}
|
||||
@ -1150,7 +1150,7 @@ func TestUserChangePasswordWithOldLog(t *testing.T) {
|
||||
as, tearDown := setupAuthStore(t)
|
||||
defer tearDown(t)
|
||||
|
||||
ctx1 := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx1 := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(1)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, err := as.Authenticate(ctx1, "foo", "bar")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -1161,7 +1161,7 @@ func TestUserChangePasswordWithOldLog(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx2 := context.WithValue(context.WithValue(context.TODO(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
ctx2 := context.WithValue(context.WithValue(t.Context(), AuthenticateParamIndex{}, uint64(2)), AuthenticateParamSimpleTokenPrefix{}, "dummy")
|
||||
_, err = as.Authenticate(ctx2, "foo", "baz")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -15,7 +15,6 @@
|
||||
package embed
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go.etcd.io/etcd/server/v3/etcdserver/api/v3client"
|
||||
@ -33,19 +32,19 @@ func TestEnableAuth(t *testing.T) {
|
||||
client := v3client.New(e.Server)
|
||||
defer client.Close()
|
||||
|
||||
_, err = client.RoleAdd(context.TODO(), "root")
|
||||
_, err = client.RoleAdd(t.Context(), "root")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = client.UserAdd(context.TODO(), "root", "root")
|
||||
_, err = client.UserAdd(t.Context(), "root", "root")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = client.UserGrantRole(context.TODO(), "root", "root")
|
||||
_, err = client.UserGrantRole(t.Context(), "root", "root")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = client.AuthEnable(context.TODO())
|
||||
_, err = client.AuthEnable(t.Context())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package rafthttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -116,7 +115,7 @@ func TestStreamReaderDialRequest(t *testing.T) {
|
||||
peerID: types.ID(2),
|
||||
tr: &Transport{streamRt: tr, ClusterID: types.ID(1), ID: types.ID(1)},
|
||||
picker: mustNewURLPicker(t, []string{"http://localhost:2380"}),
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
}
|
||||
sr.dial(tt)
|
||||
|
||||
@ -171,7 +170,7 @@ func TestStreamReaderDialResult(t *testing.T) {
|
||||
tr: &Transport{streamRt: tr, ClusterID: types.ID(1)},
|
||||
picker: mustNewURLPicker(t, []string{"http://localhost:2380"}),
|
||||
errorc: make(chan error, 1),
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
}
|
||||
|
||||
_, err := sr.dial(streamTypeMessage)
|
||||
@ -253,7 +252,7 @@ func TestStreamReaderDialDetectUnsupport(t *testing.T) {
|
||||
peerID: types.ID(2),
|
||||
tr: &Transport{streamRt: tr, ClusterID: types.ID(1)},
|
||||
picker: mustNewURLPicker(t, []string{"http://localhost:2380"}),
|
||||
ctx: context.Background(),
|
||||
ctx: t.Context(),
|
||||
}
|
||||
|
||||
_, err := sr.dial(typ)
|
||||
|
@ -168,7 +168,7 @@ func execTransaction(t *testing.T, req *pb.RequestOp) {
|
||||
defer s.Close()
|
||||
|
||||
// setup cancelled context
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
cancel()
|
||||
|
||||
request := &pb.TxnRequest{
|
||||
|
@ -986,7 +986,7 @@ func TestAddMember(t *testing.T) {
|
||||
}
|
||||
s.start()
|
||||
m := membership.Member{ID: 1234, RaftAttributes: membership.RaftAttributes{PeerURLs: []string{"foo"}}}
|
||||
_, err := s.AddMember(context.Background(), m)
|
||||
_, err := s.AddMember(t.Context(), m)
|
||||
gaction := n.Action()
|
||||
s.Stop()
|
||||
|
||||
@ -1052,7 +1052,7 @@ func TestProcessIgnoreMismatchMessage(t *testing.T) {
|
||||
if types.ID(m.To) == s.MemberID() {
|
||||
t.Fatalf("m.To (%d) is expected to mismatch s.MemberID (%d)", m.To, s.MemberID())
|
||||
}
|
||||
err := s.Process(context.Background(), m)
|
||||
err := s.Process(t.Context(), m)
|
||||
if err == nil {
|
||||
t.Fatalf("Must ignore the message and return an error")
|
||||
}
|
||||
@ -1092,7 +1092,7 @@ func TestRemoveMember(t *testing.T) {
|
||||
beHooks: serverstorage.NewBackendHooks(lg, nil),
|
||||
}
|
||||
s.start()
|
||||
_, err := s.RemoveMember(context.Background(), 1234)
|
||||
_, err := s.RemoveMember(t.Context(), 1234)
|
||||
gaction := n.Action()
|
||||
s.Stop()
|
||||
|
||||
@ -1142,7 +1142,7 @@ func TestUpdateMember(t *testing.T) {
|
||||
}
|
||||
s.start()
|
||||
wm := membership.Member{ID: 1234, RaftAttributes: membership.RaftAttributes{PeerURLs: []string{"http://127.0.0.1:1"}}}
|
||||
_, err := s.UpdateMember(context.Background(), wm)
|
||||
_, err := s.UpdateMember(t.Context(), wm)
|
||||
gaction := n.Action()
|
||||
s.Stop()
|
||||
|
||||
@ -1166,7 +1166,7 @@ func TestPublishV3(t *testing.T) {
|
||||
// simulate that request has gone through consensus
|
||||
ch <- &apply2.Result{}
|
||||
w := wait.NewWithResponse(ch)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
lg := zaptest.NewLogger(t)
|
||||
be, _ := betesting.NewDefaultTmpBackend(t)
|
||||
defer betesting.Close(t, be)
|
||||
@ -1208,7 +1208,7 @@ func TestPublishV3(t *testing.T) {
|
||||
|
||||
// TestPublishV3Stopped tests that publish will be stopped if server is stopped.
|
||||
func TestPublishV3Stopped(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
r := newRaftNode(raftNodeConfig{
|
||||
lg: zaptest.NewLogger(t),
|
||||
Node: newNodeNop(),
|
||||
@ -1236,7 +1236,7 @@ func TestPublishV3Stopped(t *testing.T) {
|
||||
|
||||
// TestPublishV3Retry tests that publish will keep retry until success.
|
||||
func TestPublishV3Retry(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
n := newNodeRecorderStream()
|
||||
|
||||
lg := zaptest.NewLogger(t)
|
||||
@ -1290,7 +1290,7 @@ func TestUpdateVersionV3(t *testing.T) {
|
||||
// simulate that request has gone through consensus
|
||||
ch <- &apply2.Result{}
|
||||
w := wait.NewWithResponse(ch)
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
lg := zaptest.NewLogger(t)
|
||||
be, _ := betesting.NewDefaultTmpBackend(t)
|
||||
defer betesting.Close(t, be)
|
||||
|
@ -226,7 +226,7 @@ func TestCheckTxn(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s, lessor := setup(t, tc.setup)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
_, _, err := Txn(ctx, zaptest.NewLogger(t), tc.txn, false, s, lessor)
|
||||
|
||||
@ -246,7 +246,7 @@ func TestCheckPut(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s, lessor := setup(t, tc.setup)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
_, _, err := Put(ctx, zaptest.NewLogger(t), lessor, s, tc.op.GetRequestPut())
|
||||
|
||||
@ -266,7 +266,7 @@ func TestCheckRange(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s, _ := setup(t, tc.setup)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
defer cancel()
|
||||
_, _, err := Range(ctx, zaptest.NewLogger(t), s, tc.op.GetRequestRange())
|
||||
|
||||
@ -314,7 +314,7 @@ func TestReadonlyTxnError(t *testing.T) {
|
||||
defer s.Close()
|
||||
|
||||
// setup cancelled context
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
cancel()
|
||||
|
||||
// put some data to prevent early termination in rangeKeys
|
||||
@ -345,7 +345,7 @@ func TestWriteTxnPanicWithoutApply(t *testing.T) {
|
||||
defer s.Close()
|
||||
|
||||
// setup cancelled context
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
cancel()
|
||||
|
||||
// write txn that puts some data and then fails in range due to cancelled context
|
||||
|
@ -65,7 +65,7 @@ func TestDowngradeSingleNode(t *testing.T) {
|
||||
c.StepMonitors()
|
||||
assert.Equal(t, newCluster(lg, 1, version.V3_6), c)
|
||||
|
||||
require.NoError(t, c.Version().DowngradeEnable(context.Background(), &version.V3_5))
|
||||
require.NoError(t, c.Version().DowngradeEnable(t.Context(), &version.V3_5))
|
||||
c.StepMonitors()
|
||||
assert.Equal(t, version.V3_5, c.clusterVersion)
|
||||
|
||||
@ -81,7 +81,7 @@ func TestDowngradeThreeNode(t *testing.T) {
|
||||
c.StepMonitors()
|
||||
assert.Equal(t, newCluster(lg, 3, version.V3_6), c)
|
||||
|
||||
require.NoError(t, c.Version().DowngradeEnable(context.Background(), &version.V3_5))
|
||||
require.NoError(t, c.Version().DowngradeEnable(t.Context(), &version.V3_5))
|
||||
c.StepMonitors()
|
||||
assert.Equal(t, version.V3_5, c.clusterVersion)
|
||||
|
||||
@ -101,7 +101,7 @@ func TestNewerMemberCanReconnectDuringDowngrade(t *testing.T) {
|
||||
c.StepMonitors()
|
||||
assert.Equal(t, newCluster(lg, 3, version.V3_6), c)
|
||||
|
||||
require.NoError(t, c.Version().DowngradeEnable(context.Background(), &version.V3_5))
|
||||
require.NoError(t, c.Version().DowngradeEnable(t.Context(), &version.V3_5))
|
||||
c.StepMonitors()
|
||||
assert.Equal(t, version.V3_5, c.clusterVersion)
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
package leasehttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@ -42,7 +41,7 @@ func TestRenewHTTP(t *testing.T) {
|
||||
ts := httptest.NewServer(NewHandler(le, waitReady))
|
||||
defer ts.Close()
|
||||
|
||||
ttl, err := RenewHTTP(context.TODO(), l.ID, ts.URL+LeasePrefix, http.DefaultTransport)
|
||||
ttl, err := RenewHTTP(t.Context(), l.ID, ts.URL+LeasePrefix, http.DefaultTransport)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -66,7 +65,7 @@ func TestTimeToLiveHTTP(t *testing.T) {
|
||||
ts := httptest.NewServer(NewHandler(le, waitReady))
|
||||
defer ts.Close()
|
||||
|
||||
resp, err := TimeToLiveHTTP(context.TODO(), l.ID, true, ts.URL+LeaseInternalPrefix, http.DefaultTransport)
|
||||
resp, err := TimeToLiveHTTP(t.Context(), l.ID, true, ts.URL+LeaseInternalPrefix, http.DefaultTransport)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -80,14 +79,14 @@ func TestTimeToLiveHTTP(t *testing.T) {
|
||||
|
||||
func TestRenewHTTPTimeout(t *testing.T) {
|
||||
testApplyTimeout(t, func(l *lease.Lease, serverURL string) error {
|
||||
_, err := RenewHTTP(context.TODO(), l.ID, serverURL+LeasePrefix, http.DefaultTransport)
|
||||
_, err := RenewHTTP(t.Context(), l.ID, serverURL+LeasePrefix, http.DefaultTransport)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func TestTimeToLiveHTTPTimeout(t *testing.T) {
|
||||
testApplyTimeout(t, func(l *lease.Lease, serverURL string) error {
|
||||
_, err := TimeToLiveHTTP(context.TODO(), l.ID, true, serverURL+LeaseInternalPrefix, http.DefaultTransport)
|
||||
_, err := TimeToLiveHTTP(t.Context(), l.ID, true, serverURL+LeaseInternalPrefix, http.DefaultTransport)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func write(tx backend.BatchTx, k, v []byte) {
|
||||
}
|
||||
|
||||
func TestBackendAutoCommitBatchIntervalHook(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
ctx, cancel := context.WithTimeout(t.Context(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
cfg := backend.DefaultBackendConfig(zaptest.NewLogger(t))
|
||||
|
@ -138,7 +138,7 @@ func TestCompactionHash(t *testing.T) {
|
||||
s := NewStore(zaptest.NewLogger(t), b, &lease.FakeLessor{}, StoreConfig{})
|
||||
defer cleanup(s, b)
|
||||
|
||||
testutil.TestCompactionHash(context.Background(), t, hashTestCase{s}, s.cfg.CompactionBatchLimit)
|
||||
testutil.TestCompactionHash(t.Context(), t, hashTestCase{s}, s.cfg.CompactionBatchLimit)
|
||||
}
|
||||
|
||||
type hashTestCase struct {
|
||||
|
@ -273,7 +273,7 @@ func testKVPutMultipleTimes(t *testing.T, f putFunc) {
|
||||
t.Errorf("#%d: rev = %d, want %d", i, rev, base+1)
|
||||
}
|
||||
|
||||
r, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{})
|
||||
r, err := s.Range(t.Context(), []byte("foo"), nil, RangeOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -384,7 +384,7 @@ func testKVPutWithSameLease(t *testing.T, f putFunc) {
|
||||
}
|
||||
|
||||
// check leaseID
|
||||
r, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{})
|
||||
r, err := s.Range(t.Context(), []byte("foo"), nil, RangeOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -412,7 +412,7 @@ func TestKVOperationInSequence(t *testing.T) {
|
||||
t.Errorf("#%d: put rev = %d, want %d", i, rev, base+1)
|
||||
}
|
||||
|
||||
r, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: base + 1})
|
||||
r, err := s.Range(t.Context(), []byte("foo"), nil, RangeOptions{Rev: base + 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -432,7 +432,7 @@ func TestKVOperationInSequence(t *testing.T) {
|
||||
t.Errorf("#%d: n = %d, rev = %d, want (%d, %d)", i, n, rev, 1, base+2)
|
||||
}
|
||||
|
||||
r, err = s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: base + 2})
|
||||
r, err = s.Range(t.Context(), []byte("foo"), nil, RangeOptions{Rev: base + 2})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -490,7 +490,7 @@ func TestKVTxnNonBlockRange(t *testing.T) {
|
||||
donec := make(chan struct{})
|
||||
go func() {
|
||||
defer close(donec)
|
||||
s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{})
|
||||
s.Range(t.Context(), []byte("foo"), nil, RangeOptions{})
|
||||
}()
|
||||
select {
|
||||
case <-donec:
|
||||
@ -516,7 +516,7 @@ func TestKVTxnOperationInSequence(t *testing.T) {
|
||||
t.Errorf("#%d: put rev = %d, want %d", i, rev, base+1)
|
||||
}
|
||||
|
||||
r, err := txn.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: base + 1})
|
||||
r, err := txn.Range(t.Context(), []byte("foo"), nil, RangeOptions{Rev: base + 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -536,7 +536,7 @@ func TestKVTxnOperationInSequence(t *testing.T) {
|
||||
t.Errorf("#%d: n = %d, rev = %d, want (%d, %d)", i, n, rev, 1, base+1)
|
||||
}
|
||||
|
||||
r, err = txn.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: base + 1})
|
||||
r, err = txn.Range(t.Context(), []byte("foo"), nil, RangeOptions{Rev: base + 1})
|
||||
if err != nil {
|
||||
t.Errorf("#%d: range error (%v)", i, err)
|
||||
}
|
||||
@ -595,7 +595,7 @@ func TestKVCompactReserveLastValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("#%d: unexpect compact error %v", i, err)
|
||||
}
|
||||
r, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: tt.rev + 1})
|
||||
r, err := s.Range(t.Context(), []byte("foo"), nil, RangeOptions{Rev: tt.rev + 1})
|
||||
if err != nil {
|
||||
t.Errorf("#%d: unexpect range error %v", i, err)
|
||||
}
|
||||
@ -697,7 +697,7 @@ func TestKVRestore(t *testing.T) {
|
||||
tt(s)
|
||||
var kvss [][]mvccpb.KeyValue
|
||||
for k := int64(0); k < 10; k++ {
|
||||
r, _ := s.Range(context.TODO(), []byte("a"), []byte("z"), RangeOptions{Rev: k})
|
||||
r, _ := s.Range(t.Context(), []byte("a"), []byte("z"), RangeOptions{Rev: k})
|
||||
kvss = append(kvss, r.KVs)
|
||||
}
|
||||
|
||||
@ -715,7 +715,7 @@ func TestKVRestore(t *testing.T) {
|
||||
testutil.WaitSchedule()
|
||||
var nkvss [][]mvccpb.KeyValue
|
||||
for k := int64(0); k < 10; k++ {
|
||||
r, _ := ns.Range(context.TODO(), []byte("a"), []byte("z"), RangeOptions{Rev: k})
|
||||
r, _ := ns.Range(t.Context(), []byte("a"), []byte("z"), RangeOptions{Rev: k})
|
||||
nkvss = append(nkvss, r.KVs)
|
||||
}
|
||||
cleanup(ns, b)
|
||||
@ -759,7 +759,7 @@ func TestKVSnapshot(t *testing.T) {
|
||||
|
||||
ns := NewStore(zaptest.NewLogger(t), b, &lease.FakeLessor{}, StoreConfig{})
|
||||
defer ns.Close()
|
||||
r, err := ns.Range(context.TODO(), []byte("a"), []byte("z"), RangeOptions{})
|
||||
r, err := ns.Range(t.Context(), []byte("a"), []byte("z"), RangeOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("unexpect range error (%v)", err)
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
package mvcc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -70,7 +69,7 @@ func benchmarkStoreRange(b *testing.B, n int) {
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
s.Range(context.TODO(), begin, end, RangeOptions{})
|
||||
s.Range(b.Context(), begin, end, RangeOptions{})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
package mvcc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
@ -139,7 +138,7 @@ func TestCompactAllAndRestore(t *testing.T) {
|
||||
if s1.Rev() != rev {
|
||||
t.Errorf("rev = %v, want %v", s1.Rev(), rev)
|
||||
}
|
||||
_, err = s1.Range(context.TODO(), []byte("foo"), nil, RangeOptions{})
|
||||
_, err = s1.Range(t.Context(), []byte("foo"), nil, RangeOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("unexpect range error %v", err)
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package mvcc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
@ -218,7 +217,7 @@ func TestStoreRange(t *testing.T) {
|
||||
b.tx.rangeRespc <- tt.r
|
||||
fi.indexRangeRespc <- tt.idxr
|
||||
|
||||
ret, err := s.Range(context.TODO(), []byte("foo"), []byte("goo"), ro)
|
||||
ret, err := s.Range(t.Context(), []byte("foo"), []byte("goo"), ro)
|
||||
if err != nil {
|
||||
t.Errorf("#%d: err = %v, want nil", i, err)
|
||||
}
|
||||
@ -469,7 +468,7 @@ func TestRestoreDelete(t *testing.T) {
|
||||
defer s.Close()
|
||||
for i := 0; i < 20; i++ {
|
||||
ks := fmt.Sprintf("foo-%d", i)
|
||||
r, err := s.Range(context.TODO(), []byte(ks), nil, RangeOptions{})
|
||||
r, err := s.Range(t.Context(), []byte(ks), nil, RangeOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -519,7 +518,7 @@ func TestRestoreContinueUnfinishedCompaction(t *testing.T) {
|
||||
// wait for scheduled compaction to be finished
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
if _, err := s.Range(context.TODO(), []byte("foo"), nil, RangeOptions{Rev: 1}); !errors.Is(err, ErrCompacted) {
|
||||
if _, err := s.Range(t.Context(), []byte("foo"), nil, RangeOptions{Rev: 1}); !errors.Is(err, ErrCompacted) {
|
||||
t.Errorf("range on compacted rev error = %v, want %v", err, ErrCompacted)
|
||||
}
|
||||
// check the key in backend is deleted
|
||||
@ -757,7 +756,7 @@ func TestConcurrentReadNotBlockingWrite(t *testing.T) {
|
||||
// readTx2 simulates a short read request
|
||||
readTx2 := s.Read(ConcurrentReadTxMode, traceutil.TODO())
|
||||
ro := RangeOptions{Limit: 1, Rev: 0, Count: false}
|
||||
ret, err := readTx2.Range(context.TODO(), []byte("foo"), nil, ro)
|
||||
ret, err := readTx2.Range(t.Context(), []byte("foo"), nil, ro)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to range: %v", err)
|
||||
}
|
||||
@ -774,7 +773,7 @@ func TestConcurrentReadNotBlockingWrite(t *testing.T) {
|
||||
}
|
||||
readTx2.End()
|
||||
|
||||
ret, err = readTx1.Range(context.TODO(), []byte("foo"), nil, ro)
|
||||
ret, err = readTx1.Range(t.Context(), []byte("foo"), nil, ro)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to range: %v", err)
|
||||
}
|
||||
@ -841,7 +840,7 @@ func TestConcurrentReadTxAndWrite(t *testing.T) {
|
||||
tx := s.Read(ConcurrentReadTxMode, traceutil.TODO())
|
||||
mu.Unlock()
|
||||
// get all keys in backend store, and compare with wKVs
|
||||
ret, err := tx.Range(context.TODO(), []byte("\x00000000"), []byte("\xffffffff"), RangeOptions{})
|
||||
ret, err := tx.Range(t.Context(), []byte("\x00000000"), []byte("\xffffffff"), RangeOptions{})
|
||||
tx.End()
|
||||
if err != nil {
|
||||
t.Errorf("failed to range keys: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user