diff --git a/api/renewer.go b/api/renewer.go index 2749f7213adb..86107555db17 100644 --- a/api/renewer.go +++ b/api/renewer.go @@ -341,10 +341,7 @@ func (r *Renewer) sleepDuration(base time.Duration) time.Duration { // calculateGrace calculates the grace period based on a reasonable set of // assumptions given the total lease time; it also adds some jitter to not have -// clients be in sync. We calculate this continuously so long as the new lease -// duration is greater than the previous; no change means we don't need to -// recalculate, and if the lease duration keeps decreasing we've hit max and -// want to be able to rely on this. +// clients be in sync. func (r *Renewer) calculateGrace(leaseDuration time.Duration) { if leaseDuration == 0 { r.grace = 0 diff --git a/api/renewer_integration_test.go b/api/renewer_integration_test.go index 50a775e1261c..3cc1ec05b387 100644 --- a/api/renewer_integration_test.go +++ b/api/renewer_integration_test.go @@ -146,15 +146,20 @@ func TestRenewer_Renew(t *testing.T) { t.Errorf("no renewal") } - select { - case err := <-v.DoneCh(): - if err != nil { - t.Fatal(err) + outer: + for { + select { + case err := <-v.DoneCh(): + if err != nil { + t.Fatal(err) + } + break outer + case <-v.RenewCh(): + continue outer + case <-time.After(3 * time.Second): + t.Errorf("no data") + break outer } - case renew := <-v.RenewCh(): - t.Fatalf("should not have renewed (lease should be up): %#v", renew) - case <-time.After(3 * time.Second): - t.Errorf("no data") } }) @@ -205,15 +210,20 @@ func TestRenewer_Renew(t *testing.T) { t.Errorf("no renewal") } - select { - case err := <-v.DoneCh(): - if err != nil { - t.Fatal(err) + outer: + for { + select { + case err := <-v.DoneCh(): + if err != nil { + t.Fatal(err) + } + break outer + case <-v.RenewCh(): + continue outer + case <-time.After(3 * time.Second): + t.Errorf("no data") + break outer } - case renew := <-v.RenewCh(): - t.Fatalf("should not have renewed (lease should be up): %#v", renew) - case <-time.After(3 * time.Second): - t.Errorf("no data") } }) }) diff --git a/api/renewer_test.go b/api/renewer_test.go index 262484e0fa01..d0b828b451ed 100644 --- a/api/renewer_test.go +++ b/api/renewer_test.go @@ -41,7 +41,6 @@ func TestRenewer_NewRenewer(t *testing.T) { }, &Renewer{ secret: &Secret{}, - grace: DefaultRenewerGrace, }, false, },