Change backoff behaviour so that Failure returns planned end time (#1288)

This commit is contained in:
Neil Alexander 2020-08-20 14:58:53 +01:00 committed by GitHub
parent 5ad47d3b3d
commit 0fea056db4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 9 deletions

View file

@ -10,7 +10,7 @@ import (
func TestBackoff(t *testing.T) {
stats := Statistics{
FailuresUntilBlacklist: 5,
FailuresUntilBlacklist: 7,
}
server := ServerStatistics{
statistics: &stats,
@ -41,10 +41,20 @@ func TestBackoff(t *testing.T) {
// Get the duration.
duration, blacklist := server.BackoffIfRequired(backingOff, interrupt)
// Register another failure for good measure. This should have no
// side effects since a backoff is already in progress. If it does
// then we'll fail.
until, blacklisted := server.Failure()
if time.Until(until) > duration {
t.Fatal("Failure produced unexpected side effect when it shouldn't have")
}
// Check if we should be blacklisted by now.
if i > stats.FailuresUntilBlacklist {
if i >= stats.FailuresUntilBlacklist {
if !blacklist {
t.Fatalf("Backoff %d should have resulted in blacklist but didn't", i)
} else if blacklist != blacklisted {
t.Fatalf("BackoffIfRequired and Failure returned different blacklist values")
} else {
t.Logf("Backoff %d is blacklisted as expected", i)
continue