mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests/common/lease: Wait for correct lease list response
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 ```
This commit is contained in:
parent
6c974a3e31
commit
f71196d113
@ -127,20 +127,30 @@ func TestLeaseGrantAndList(t *testing.T) {
|
||||
t.Logf("Created cluster and client")
|
||||
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)
|
||||
t.Logf("Grant returned: resp:%s err:%v", leaseResp.String(), err)
|
||||
require.NoError(t, err)
|
||||
createdLeases = append(createdLeases, leaseResp.ID)
|
||||
lastRev = leaseResp.GetRevision()
|
||||
}
|
||||
|
||||
resp, err := cc.LeaseList()
|
||||
t.Logf("Lease list returned: resp:%s err:%v", resp.String(), err)
|
||||
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
|
||||
}, 2*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)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user