Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx authored and ti-chi-bot committed Aug 10, 2023
1 parent abefc6c commit 5bf59c9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions server/election/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,34 @@ func (s *testLeaseSuite) TestLease(c *C) {
time.Sleep((defaultLeaseTimeout + 1) * time.Second)
c.Check(lease1.IsExpired(), IsTrue)
}

func TestLeaseKeepAlive(t *testing.T) {

Check failure on line 108 in server/election/lease_test.go

View workflow job for this annotation

GitHub Actions / statics

undeclared name: `testing` (typecheck)
re := require.New(t)

Check failure on line 109 in server/election/lease_test.go

View workflow job for this annotation

GitHub Actions / statics

undeclared name: `require` (typecheck)
cfg := etcdutil.NewTestSingleConfig(t)

Check failure on line 110 in server/election/lease_test.go

View workflow job for this annotation

GitHub Actions / statics

too many arguments in call to etcdutil.NewTestSingleConfig (typecheck)
etcd, err := embed.StartEtcd(cfg)
defer func() {
etcd.Close()
}()
re.NoError(err)

ep := cfg.LCUrls[0].String()
client, err := clientv3.New(clientv3.Config{
Endpoints: []string{ep},
})
re.NoError(err)

<-etcd.Server.ReadyNotify()

// Create the lease.
lease := &lease{
Purpose: "test_lease",
client: client,
lease: clientv3.NewLease(client),
}

re.NoError(lease.Grant(defaultLeaseTimeout))
ch := lease.keepAliveWorker(context.Background(), 2*time.Second)
time.Sleep(2 * time.Second)
<-ch
re.NoError(lease.Close())
}

0 comments on commit 5bf59c9

Please sign in to comment.