github.com/lfch/etcd-io/tests/v3@v3.0.0-20221004140520-eac99acd3e9d/common/status_test.go (about) 1 // Copyright 2022 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package common 16 17 import ( 18 "context" 19 "testing" 20 "time" 21 22 clientv3 "github.com/lfch/etcd-io/client/v3" 23 "github.com/lfch/etcd-io/tests/v3/framework" 24 "github.com/lfch/etcd-io/tests/v3/framework/testutils" 25 ) 26 27 func TestStatus(t *testing.T) { 28 29 testRunner.BeforeTest(t) 30 31 for _, tc := range clusterTestCases { 32 t.Run(tc.name, func(t *testing.T) { 33 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 34 defer cancel() 35 clus := testRunner.NewCluster(ctx, t, tc.config) 36 defer clus.Close() 37 cc := framework.MustClient(clus.Client(clientv3.AuthConfig{})) 38 39 testutils.ExecuteUntil(ctx, t, func() { 40 rs, err := cc.Status(ctx) 41 if err != nil { 42 t.Fatalf("could not get status, err: %s", err) 43 } 44 if len(rs) != tc.config.ClusterSize { 45 t.Fatalf("wrong number of status responses. expected:%d, got:%d ", tc.config.ClusterSize, len(rs)) 46 } 47 memberIds := make(map[uint64]struct{}) 48 for _, r := range rs { 49 if r == nil { 50 t.Fatalf("status response is nil") 51 } 52 memberIds[r.Header.MemberId] = struct{}{} 53 } 54 if len(rs) != len(memberIds) { 55 t.Fatalf("found duplicated members") 56 } 57 }) 58 }) 59 } 60 }