-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update lease renewer logic #4090
Changes from all commits
8eeb075
8f97444
9a14905
1631036
c4713e0
2a5da57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,8 +109,8 @@ func TestRenewer_Renew(t *testing.T) { | |
"creation_statements": `` + | ||
`CREATE ROLE "{{name}}" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';` + | ||
`GRANT SELECT ON ALL TABLES IN SCHEMA public TO "{{name}}";`, | ||
"default_ttl": "1s", | ||
"max_ttl": "3s", | ||
"default_ttl": "5s", | ||
"max_ttl": "10s", | ||
}); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -139,22 +139,28 @@ func TestRenewer_Renew(t *testing.T) { | |
if !renew.Secret.Renewable { | ||
t.Errorf("expected lease to be renewable: %#v", renew) | ||
} | ||
if renew.Secret.LeaseDuration > 2 { | ||
t.Errorf("expected lease to < 2s: %#v", renew) | ||
if renew.Secret.LeaseDuration > 5 { | ||
t.Errorf("expected lease to <= 5s: %#v", renew) | ||
} | ||
case <-time.After(3 * time.Second): | ||
case <-time.After(5 * time.Second): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because for any given renewal it should use the default lease so we should expect activity within the default lease period, not max lease period. |
||
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 renew := <-v.RenewCh(): | ||
t.Logf("renew called, remaining lease duration: %d", renew.Secret.LeaseDuration) | ||
continue outer | ||
case <-time.After(5 * time.Second): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
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 +211,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") | ||
} | ||
}) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we calculate the new grace if the lease duration doesn't change, which could be a likely common thing? In other words, should this be
leaseDuration >= priorDuration
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the lease duration doesn't change, the grace period would be within the same parameters. Recalculating it would just shift the amount of random jitter, which if it's truly random won't either help or hurt, so can be skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍