mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Fix logic fail
This commit is contained in:
parent
b4d157c6cf
commit
12f2388777
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
// 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)
|
||||
}
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue