Skip to content

Commit

Permalink
update etcd driver
Browse files Browse the repository at this point in the history
  • Loading branch information
dxyinme committed Dec 30, 2023
1 parent f675de5 commit a21ebf7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
11 changes: 5 additions & 6 deletions driver/etcddriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const (
etcdDefaultLease = 5 // min lease time
etcdDialTimeout = 3 * time.Second
etcdBusinessTimeout = 5 * time.Second
etcdBusinessTimeout = 6 * time.Second
)

type EtcdDriver struct {
Expand Down Expand Up @@ -160,13 +160,12 @@ label:
e.logger.Warnf("lease failed, release")
goto label
}
if leaseResponse.ID != e.leaseID {
e.logger.Warnf("lease id not equal, leaseID=%d,expectedID=%d", leaseResponse.ID, e.leaseID)
goto label
}
e.logger.Infof("lease id: %d, TTL: %d", leaseResponse.ID, leaseResponse.TTL)
}
case <-time.After(etcdBusinessTimeout):
{
e.logger.Errorf("ectd cli keepalive timeout, release")
goto label
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions driver/etcddriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestEtcdDriver_GetNodes(t *testing.T) {
etcdsvr := integration.NewLazyCluster()
defer etcdsvr.Terminate()
N := 10
drvs := make([]driver.DriverV2, 0)
drvs := make([]driver.DriverV2, N)
for i := 0; i < N; i++ {
drv := testFuncNewEtcdDriver(clientv3.Config{
Endpoints: etcdsvr.EndpointsV3(),
Expand All @@ -33,17 +33,17 @@ func TestEtcdDriver_GetNodes(t *testing.T) {
drv.Init(t.Name(), driver.NewTimeoutOption(5*time.Second), driver.NewLoggerOption(dlog.NewLoggerForTest(t)))
err := drv.Start(context.Background())
require.Nil(t, err)
drvs = append(drvs, drv)
drvs[i] = drv
}
<-time.After(5 * time.Second)
for _, v := range drvs {
nodes, err := v.GetNodes(context.Background())
for _, drv := range drvs {
nodes, err := drv.GetNodes(context.Background())
require.Nil(t, err)
require.Equal(t, N, len(nodes))
}

for _, v := range drvs {
v.Stop(context.Background())
for _, drv := range drvs {
drv.Stop(context.Background())
}
}

Expand Down
2 changes: 1 addition & 1 deletion driver/redisdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func testFuncNewRedisDriver(addr string) driver.DriverV2 {
log.Println("redis=", addr)
log.Printf("redis=%s", addr)
redisCli := redis.NewClient(&redis.Options{
Addr: addr,
})
Expand Down

0 comments on commit a21ebf7

Please sign in to comment.