Skip to content

Commit

Permalink
tests/common/lease: Wait for correct lease list response
Browse files Browse the repository at this point in the history
We don't consistently reach the same etcd server during the lifetime of
a test and in some cases, this means that this test will flake if an
etcd server was slow to update its state and the test hits the outdated
server.

Here we switch to using an `Eventually` case which will wait upto a
second for the expected result before failing - with a 10ms gap between
invocations.

```
[tests(dani/leasefix)] $ gotestsum -- ./common -tags integration -count 100 -timeout 15m -run TestLeaseGrantAndList
✓  common (2m26.71s)

DONE 1600 tests in 147.258s
```
  • Loading branch information
endocrimes committed Apr 4, 2022
1 parent 0d5c1dc commit 32a5b39
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions tests/common/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,29 @@ func TestLeaseGrantAndList(t *testing.T) {

testutils.ExecuteWithTimeout(t, 10*time.Second, func() {
createdLeases := []clientv3.LeaseID{}
lastRev := int64(0)
for i := 0; i < nc.leaseCount; i++ {
leaseResp, err := cc.Grant(10)
require.NoError(t, err)
createdLeases = append(createdLeases, leaseResp.ID)
lastRev = leaseResp.GetRevision()
}

resp, err := cc.LeaseList()
require.NoError(t, err)
require.Len(t, resp.Leases, nc.leaseCount)
// Because we're not guarunteed to talk to the same member, wait for
// listing to eventually return true, either by the result propagaing
// or by hitting an up to date member.
leases := []clientv3.LeaseStatus{}
require.Eventually(t, func() bool {
resp, err := cc.LeaseList()
if err != nil {
return false
}
leases = resp.Leases
return resp.GetRevision() >= lastRev
}, 1*time.Second, 10*time.Millisecond)

returnedLeases := make([]clientv3.LeaseID, 0, nc.leaseCount)
for _, status := range resp.Leases {
for _, status := range leases {
returnedLeases = append(returnedLeases, status.ID)
}

Expand Down

0 comments on commit 32a5b39

Please sign in to comment.