Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
dxyinme committed Dec 30, 2023
1 parent a576ac3 commit 99b2d82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 1 addition & 7 deletions driver/etcddriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func (e *EtcdDriver) revoke(ctx context.Context) {
}

func (e *EtcdDriver) heartBeat(ctx context.Context) {
label:
leaseCh, err := e.createLease(ctx, e.nodeID)
if err != nil {
e.logger.Errorf("keep alive error, %v", err)
Expand All @@ -153,15 +152,10 @@ label:
e.logger.Infof("driver stopped")
return
}
case resp, ok := <-leaseCh:
case resp := <-leaseCh:
{
// if lease timeout, goto top of
// this function to keepalive
if !ok {
e.logger.Errorf("extend lease error, release")
goto label
}

e.logger.Infof("leaseID=%0x", resp.ID)
}
}
Expand Down
14 changes: 13 additions & 1 deletion e2e/etcddriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestEtcdDriver_GetNodes(t *testing.T) {
require.Nil(t, err)
drvs = append(drvs, drv)
}
<-time.After(5 * time.Second)
<-time.After(15 * time.Second)
for _, v := range drvs {
nodes, err := v.GetNodes(context.Background())
require.Nil(t, err)
Expand Down Expand Up @@ -91,6 +91,18 @@ func TestEtcdDriver_Stop(t *testing.T) {
nodes, err = drv2.GetNodes(context.Background())
require.Nil(t, err)
require.Len(t, nodes, 2)
nodes, err = drv1.GetNodes(context.Background())
require.Nil(t, err)
require.Len(t, nodes, 2)

// wait for 7 time extends, and re-get the nodes.
<-time.After(35 * time.Second)
nodes, err = drv2.GetNodes(context.Background())
require.Nil(t, err)
require.Len(t, nodes, 2)
nodes, err = drv1.GetNodes(context.Background())
require.Nil(t, err)
require.Len(t, nodes, 2)

drv2.Stop(context.Background())
drv1.Stop(context.Background())
Expand Down

0 comments on commit 99b2d82

Please sign in to comment.