Skip to content

Commit

Permalink
Fix some commenting and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed Mar 15, 2018
1 parent 9a14905 commit 1631036
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
5 changes: 1 addition & 4 deletions api/renewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 26 additions & 16 deletions api/renewer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})

Expand Down Expand Up @@ -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")
}
})
})
Expand Down
1 change: 0 additions & 1 deletion api/renewer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestRenewer_NewRenewer(t *testing.T) {
},
&Renewer{
secret: &Secret{},
grace: DefaultRenewerGrace,
},
false,
},
Expand Down

0 comments on commit 1631036

Please sign in to comment.