From f6a9a77ecc9d923d2f3fedef5c57af66b5f2300b Mon Sep 17 00:00:00 2001 From: Devon Hudson Date: Thu, 12 Jan 2023 11:22:10 -0700 Subject: [PATCH] Check assumed offline state in statistics test --- federationapi/statistics/statistics_test.go | 28 ++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/federationapi/statistics/statistics_test.go b/federationapi/statistics/statistics_test.go index 312c19a68..9d08c3fe0 100644 --- a/federationapi/statistics/statistics_test.go +++ b/federationapi/statistics/statistics_test.go @@ -10,8 +10,13 @@ import ( "github.com/stretchr/testify/assert" ) +const ( + FailuresUntilAssumedOffline = 2 + FailuresUntilBlacklist = 7 +) + func TestBackoff(t *testing.T) { - stats := NewStatistics(nil, 7, 2) + stats := NewStatistics(nil, FailuresUntilBlacklist, FailuresUntilAssumedOffline) server := ServerStatistics{ statistics: &stats, serverName: "test.com", @@ -50,6 +55,21 @@ func TestBackoff(t *testing.T) { } } + // Check if we should be assumed offline by now. + if i >= stats.FailuresUntilAssumedOffline { + if !assumedOffline { + t.Fatalf("Backoff %d should have resulted in assumed offline but didn't", i) + } else { + t.Logf("Backoff %d is assumed offline as expected", i) + } + } else { + if assumedOffline { + t.Fatalf("Backoff %d should not have resulted in assumed offline but did", i) + } else { + t.Logf("Backoff %d is not assumed offline as expected", i) + } + } + // Check if we should be blacklisted by now. if i >= stats.FailuresUntilBlacklist { if !blacklist { @@ -60,6 +80,12 @@ func TestBackoff(t *testing.T) { t.Logf("Backoff %d is blacklisted as expected", i) continue } + } else { + if blacklist { + t.Fatalf("Backoff %d should not have resulted in blacklist but did", i) + } else { + t.Logf("Backoff %d is not blacklisted as expected", i) + } } // Check if the duration is what we expect.