diff --git a/server/etcdserver/server_test.go b/server/etcdserver/server_test.go index ea88987d3838..e875bfe5a712 100644 --- a/server/etcdserver/server_test.go +++ b/server/etcdserver/server_test.go @@ -55,6 +55,7 @@ import ( "go.etcd.io/etcd/server/v3/mock/mockstore" "go.etcd.io/etcd/server/v3/mock/mockwait" serverstorage "go.etcd.io/etcd/server/v3/storage" + "go.etcd.io/etcd/server/v3/storage/backend" betesting "go.etcd.io/etcd/server/v3/storage/backend/testing" "go.etcd.io/etcd/server/v3/storage/mvcc" "go.etcd.io/etcd/server/v3/storage/schema" @@ -181,6 +182,7 @@ func TestDoBadLocalAction(t *testing.T) { // TestApplyRepeat tests that server handles repeat raft messages gracefully func TestApplyRepeat(t *testing.T) { + lg := zaptest.NewLogger(t) n := newNodeConfChangeCommitterStream() n.readyc <- raft.Ready{ SoftState: &raft.SoftState{RaftState: raft.StateLeader}, @@ -188,6 +190,9 @@ func TestApplyRepeat(t *testing.T) { cl := newTestCluster(t, nil) st := v2store.New() cl.SetStore(v2store.New()) + be, _ := betesting.NewDefaultTmpBackend(t) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) + cl.AddMember(&membership.Member{ID: 1234}, true) r := newRaftNode(raftNodeConfig{ lg: zaptest.NewLogger(t), @@ -490,7 +495,9 @@ func TestApplyRequest(t *testing.T) { } func TestApplyRequestOnAdminMemberAttributes(t *testing.T) { - cl := newTestCluster(t, []*membership.Member{{ID: 1}}) + be, _ := betesting.NewDefaultTmpBackend(t) + defer betesting.Close(t, be) + cl := newTestClusterWithBackend(t, []*membership.Member{{ID: 1}}, be) srv := &EtcdServer{ lgMu: new(sync.RWMutex), lg: zaptest.NewLogger(t), @@ -513,8 +520,14 @@ func TestApplyRequestOnAdminMemberAttributes(t *testing.T) { } func TestApplyConfChangeError(t *testing.T) { - cl := membership.NewCluster(zaptest.NewLogger(t)) + lg := zaptest.NewLogger(t) + be, _ := betesting.NewDefaultTmpBackend(t) + defer betesting.Close(t, be) + + cl := membership.NewCluster(lg) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) cl.SetStore(v2store.New()) + for i := 1; i <= 4; i++ { cl.AddMember(&membership.Member{ID: types.ID(i)}, true) } @@ -601,8 +614,14 @@ func TestApplyConfChangeError(t *testing.T) { } func TestApplyConfChangeShouldStop(t *testing.T) { - cl := membership.NewCluster(zaptest.NewLogger(t)) + lg := zaptest.NewLogger(t) + be, _ := betesting.NewDefaultTmpBackend(t) + defer betesting.Close(t, be) + + cl := membership.NewCluster(lg) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) cl.SetStore(v2store.New()) + for i := 1; i <= 3; i++ { cl.AddMember(&membership.Member{ID: types.ID(i)}, true) } @@ -611,7 +630,6 @@ func TestApplyConfChangeShouldStop(t *testing.T) { Node: newNodeNop(), transport: newNopTransporter(), }) - lg := zaptest.NewLogger(t) srv := &EtcdServer{ lgMu: new(sync.RWMutex), lg: lg, @@ -648,13 +666,15 @@ func TestApplyConfChangeShouldStop(t *testing.T) { // where consistIndex equals to applied index. func TestApplyConfigChangeUpdatesConsistIndex(t *testing.T) { lg := zaptest.NewLogger(t) + be, _ := betesting.NewDefaultTmpBackend(t) + defer betesting.Close(t, be) cl := membership.NewCluster(zaptest.NewLogger(t)) cl.SetStore(v2store.New()) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) + cl.AddMember(&membership.Member{ID: types.ID(1)}, true) - be, _ := betesting.NewDefaultTmpBackend(t) - defer betesting.Close(t, be) schema.CreateMetaBucket(be.BatchTx()) ci := cindex.NewConsistentIndex(be) @@ -732,6 +752,9 @@ func TestApplyMultiConfChangeShouldStop(t *testing.T) { lg := zaptest.NewLogger(t) cl := membership.NewCluster(lg) cl.SetStore(v2store.New()) + be, _ := betesting.NewDefaultTmpBackend(t) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) + for i := 1; i <= 5; i++ { cl.AddMember(&membership.Member{ID: types.ID(i)}, true) } @@ -1248,6 +1271,8 @@ func TestConcurrentApplyAndSnapshotV3(t *testing.T) { st := v2store.New() cl := membership.NewCluster(lg) cl.SetStore(st) + be, _ := betesting.NewDefaultTmpBackend(t) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) testdir := t.TempDir() if err := os.MkdirAll(testdir+"/member/snap", 0755); err != nil { @@ -1264,7 +1289,6 @@ func TestConcurrentApplyAndSnapshotV3(t *testing.T) { storage: mockstorage.NewStorageRecorder(testdir), raftStorage: rs, }) - be, _ := betesting.NewDefaultTmpBackend(t) ci := cindex.NewConsistentIndex(be) s := &EtcdServer{ lgMu: new(sync.RWMutex), @@ -1345,6 +1369,10 @@ func TestAddMember(t *testing.T) { cl := newTestCluster(t, nil) st := v2store.New() cl.SetStore(st) + be, _ := betesting.NewDefaultTmpBackend(t) + defer betesting.Close(t, be) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) + r := newRaftNode(raftNodeConfig{ lg: lg, Node: n, @@ -1391,6 +1419,9 @@ func TestRemoveMember(t *testing.T) { cl := newTestCluster(t, nil) st := v2store.New() cl.SetStore(v2store.New()) + be, _ := betesting.NewDefaultTmpBackend(t) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) + cl.AddMember(&membership.Member{ID: 1234}, true) r := newRaftNode(raftNodeConfig{ lg: lg, @@ -1430,6 +1461,8 @@ func TestRemoveMember(t *testing.T) { // TestUpdateMember tests RemoveMember can propose and perform node update. func TestUpdateMember(t *testing.T) { lg := zaptest.NewLogger(t) + be, _ := betesting.NewDefaultTmpBackend(t) + defer betesting.Close(t, be) n := newNodeConfChangeCommitterRecorder() n.readyc <- raft.Ready{ SoftState: &raft.SoftState{RaftState: raft.StateLeader}, @@ -1437,6 +1470,7 @@ func TestUpdateMember(t *testing.T) { cl := newTestCluster(t, nil) st := v2store.New() cl.SetStore(st) + cl.SetBackend(schema.NewMembershipBackend(lg, be)) cl.AddMember(&membership.Member{ID: 1234}, true) r := newRaftNode(raftNodeConfig{ lg: lg, @@ -1903,6 +1937,16 @@ func newTestCluster(t testing.TB, membs []*membership.Member) *membership.RaftCl return c } +func newTestClusterWithBackend(t testing.TB, membs []*membership.Member, be backend.Backend) *membership.RaftCluster { + lg := zaptest.NewLogger(t) + c := membership.NewCluster(lg) + c.SetBackend(schema.NewMembershipBackend(lg, be)) + for _, m := range membs { + c.AddMember(m, true) + } + return c +} + type nopTransporter struct{} func newNopTransporter() rafthttp.Transporter {