From 12f2388777e721075a9401bfe69febc51b578aca Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 7 Aug 2020 17:32:12 +0100 Subject: [PATCH] Fix logic fail --- federationsender/statistics/statistics.go | 10 ++-------- .../statistics/statistics_test.go | 19 +++---------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/federationsender/statistics/statistics.go b/federationsender/statistics/statistics.go index 5fcd5806b..381783d2b 100644 --- a/federationsender/statistics/statistics.go +++ b/federationsender/statistics/statistics.go @@ -125,14 +125,8 @@ func (s *ServerStatistics) BackoffIfRequired(backingOff atomic.Bool, interrupt < return 0 } - // Work out how many times we've backed off so far. If we - // have passed the failure counter then we can stop backing - // off - we've done our time. + // Work out how many times we've backed off so far. count := s.backoffCount.Inc() - if count >= s.failCounter.Load() { - s.backoffStarted.Store(false) - return 0 - } // Notify the destination queue that we're backing off now. backingOff.Store(true) @@ -140,7 +134,7 @@ func (s *ServerStatistics) BackoffIfRequired(backingOff atomic.Bool, interrupt < // Work out how long we should be backing off for. duration := time.Second * time.Duration(math.Exp2(float64(count))) - logrus.Debugf("Backing off %q for %d", s.serverName, duration) + logrus.Infof("Backing off %q for %s", s.serverName, duration) // Wait for either an interruption or for the backoff to // complete. diff --git a/federationsender/statistics/statistics_test.go b/federationsender/statistics/statistics_test.go index 3fc14db9f..6783825c7 100644 --- a/federationsender/statistics/statistics_test.go +++ b/federationsender/statistics/statistics_test.go @@ -50,22 +50,9 @@ func TestBackoff(t *testing.T) { duration := server.BackoffIfRequired(backingOff, interrupt) t.Logf("Backoff %d is for %s", i, duration) - // If we were below the number of failures that we simulated - // then we should expect a backoff that is exponentially - // related. Otherwise, if we've gone beyond the number of - // failures then we should expect no backoff at all. - if i < failures { - // We're expecting backoff here because we're under the - // failure count. - if wanted := time.Second * time.Duration(math.Exp2(float64(i))); duration != wanted { - t.Fatalf("Backoff should have been %s but was %s", wanted, duration) - } - } else { - // We aren't expecting backoff here because we've exceeded - // the failure count, so our backoff is "complete". - if duration != 0 { - t.Fatalf("Backoff should have been zero but was %s", duration) - } + // Check if the duration is what we expect. + if wanted := time.Second * time.Duration(math.Exp2(float64(i))); duration != wanted { + t.Fatalf("Backoff should have been %s but was %s", wanted, duration) } } }