diff --git a/tests/common/member_test.go b/tests/common/member_test.go new file mode 100644 index 000000000..f1b6be3ae --- /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 657b0eaf5..a80642398 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 83a1ba136..631b7263e 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 dc0565ad2..a7ded291a 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) }