diff --git a/driver/etcddriver.go b/driver/etcddriver.go index cd5bd78..3a32fe1 100644 --- a/driver/etcddriver.go +++ b/driver/etcddriver.go @@ -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 { @@ -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 - } } } } diff --git a/driver/etcddriver_test.go b/driver/etcddriver_test.go index e0f8225..8985356 100644 --- a/driver/etcddriver_test.go +++ b/driver/etcddriver_test.go @@ -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(), @@ -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()) } } diff --git a/driver/redisdriver_test.go b/driver/redisdriver_test.go index 4cf380f..6fedaa9 100644 --- a/driver/redisdriver_test.go +++ b/driver/redisdriver_test.go @@ -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, })