github.com/lfch/etcd-io/tests/v3@v3.0.0-20221004140520-eac99acd3e9d/functional/tester/checker_short_ttl_lease_expire.go (about) 1 // Copyright 2018 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 tester 16 17 import ( 18 "fmt" 19 "time" 20 21 "github.com/lfch/etcd-io/client/v3" 22 "github.com/lfch/etcd-io/tests/v3/functional/rpcpb" 23 24 "go.uber.org/zap" 25 "google.golang.org/grpc" 26 ) 27 28 type shortTTLLeaseExpireChecker struct { 29 ctype rpcpb.Checker 30 lg *zap.Logger 31 m *rpcpb.Member 32 ls *leaseStresser 33 cli *clientv3.Client 34 } 35 36 func newShortTTLLeaseExpireChecker(ls *leaseStresser) Checker { 37 return &shortTTLLeaseExpireChecker{ 38 ctype: rpcpb.Checker_SHORT_TTL_LEASE_EXPIRE, 39 lg: ls.lg, 40 m: ls.m, 41 ls: ls, 42 } 43 } 44 45 func (lc *shortTTLLeaseExpireChecker) Type() rpcpb.Checker { 46 return lc.ctype 47 } 48 49 func (lc *shortTTLLeaseExpireChecker) EtcdClientEndpoints() []string { 50 return []string{lc.m.EtcdClientEndpoint} 51 } 52 53 func (lc *shortTTLLeaseExpireChecker) Check() error { 54 if lc.ls == nil { 55 return nil 56 } 57 if lc.ls != nil && lc.ls.alivedLeasesWithShortTTL == nil { 58 return nil 59 } 60 61 cli, err := lc.m.CreateEtcdClient(grpc.WithBackoffMaxDelay(time.Second)) 62 if err != nil { 63 return fmt.Errorf("%v (%q)", err, lc.m.EtcdClientEndpoint) 64 } 65 defer func() { 66 if cli != nil { 67 cli.Close() 68 } 69 }() 70 lc.cli = cli 71 if err := check(lc.lg, lc.cli, false, lc.ls.alivedLeasesWithShortTTL.leases); err != nil { 72 lc.lg.Error("failed to check alivedLeasesWithShortTTL", zap.Error(err)) 73 return err 74 } 75 lc.lg.Info("check alivedLeasesWithShortTTL succ", zap.Int("num", len(lc.ls.alivedLeasesWithShortTTL.leases))) 76 return nil 77 }