From 13d20f8d289ffe822217bd4a5f8bbf48bbea1ca6 Mon Sep 17 00:00:00 2001 From: Clark Date: Tue, 26 Jul 2022 22:44:24 +0800 Subject: [PATCH] tests: Migrate member list tests to common framework Signed-off-by: Clark --- tests/common/member_test.go | 53 +++++++++++++++++++++++++++++++++ tests/e2e/ctl_v3_member_test.go | 12 -------- tests/framework/integration.go | 4 +++ tests/framework/interface.go | 2 ++ 4 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 tests/common/member_test.go diff --git a/tests/common/member_test.go b/tests/common/member_test.go new file mode 100644 index 00000000000..f1b6be3aef0 --- /dev/null +++ b/tests/common/member_test.go @@ -0,0 +1,53 @@ +// Copyright 2022 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package common + +import ( + "context" + "go.etcd.io/etcd/tests/v3/framework/testutils" + "testing" + "time" +) + +func TestMemberList(t *testing.T) { + testRunner.BeforeTest(t) + + for _, tc := range clusterTestCases { + t.Run(tc.name, func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + clus := testRunner.NewCluster(ctx, t, tc.config) + defer clus.Close() + cc := clus.Client() + + testutils.ExecuteUntil(ctx, t, func() { + resp, err := cc.MemberList() + if err != nil { + t.Fatalf("could not get member list, err: %s", err) + } + expectNum := len(clus.Members()) + gotNum := len(resp.Members) + if expectNum != gotNum { + t.Fatalf("number of members not equal, expect: %d, got: %d", expectNum, gotNum) + } + for _, m := range resp.Members { + if len(m.ClientURLs) == 0 { + t.Fatalf("member is not started, memberId:%d, memberName:%s", m.ID, m.Name) + } + } + }) + }) + } +} diff --git a/tests/e2e/ctl_v3_member_test.go b/tests/e2e/ctl_v3_member_test.go index 657b0eaf5ed..a80642398dd 100644 --- a/tests/e2e/ctl_v3_member_test.go +++ b/tests/e2e/ctl_v3_member_test.go @@ -28,18 +28,6 @@ import ( func TestCtlV3MemberList(t *testing.T) { testCtl(t, memberListTest) } func TestCtlV3MemberListWithHex(t *testing.T) { testCtl(t, memberListWithHexTest) } -func TestCtlV3MemberListNoTLS(t *testing.T) { - testCtl(t, memberListTest, withCfg(*e2e.NewConfigNoTLS())) -} -func TestCtlV3MemberListClientTLS(t *testing.T) { - testCtl(t, memberListTest, withCfg(*e2e.NewConfigClientTLS())) -} -func TestCtlV3MemberListClientAutoTLS(t *testing.T) { - testCtl(t, memberListTest, withCfg(*e2e.NewConfigClientAutoTLS())) -} -func TestCtlV3MemberListPeerTLS(t *testing.T) { - testCtl(t, memberListTest, withCfg(*e2e.NewConfigPeerTLS())) -} func TestCtlV3MemberRemove(t *testing.T) { testCtl(t, memberRemoveTest, withQuorum(), withNoStrictReconfig()) } diff --git a/tests/framework/integration.go b/tests/framework/integration.go index 83a1ba136e2..631b7263e69 100644 --- a/tests/framework/integration.go +++ b/tests/framework/integration.go @@ -372,3 +372,7 @@ func getOps(ss []string) ([]clientv3.Op, error) { } return ops, nil } + +func (c integrationClient) MemberList() (*clientv3.MemberListResponse, error) { + return c.Client.MemberList(c.ctx) +} diff --git a/tests/framework/interface.go b/tests/framework/interface.go index dc0565ad2ce..a7ded291a88 100644 --- a/tests/framework/interface.go +++ b/tests/framework/interface.go @@ -70,4 +70,6 @@ type Client interface { RoleDelete(role string) (*clientv3.AuthRoleDeleteResponse, error) Txn(compares, ifSucess, ifFail []string, o config.TxnOptions) (*clientv3.TxnResponse, error) + + MemberList() (*clientv3.MemberListResponse, error) }