go.fuchsia.dev/jiri@v0.0.0-20240502161911-b66513b29486/retry/retry_test.go (about) 1 // Copyright 2020 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package retry 6 7 import ( 8 "testing" 9 "time" 10 ) 11 12 func TestExponentialBackOff(t *testing.T) { 13 backoff := newExponentialBackoff(5, 64, 2) 14 val := backoff.nextBackoff() 15 if val < 5*time.Second || val > 15*time.Second { 16 t.Errorf("expecting backoff between 5 to 15 secs, got %v", val) 17 } 18 val = backoff.nextBackoff() 19 if val < 10*time.Second || val > 25*time.Second { 20 t.Errorf("expecting backoff between 10 to 25 secs, got %v", val) 21 } 22 val = backoff.nextBackoff() 23 if val < 20*time.Second || val > 35*time.Second { 24 t.Errorf("expecting backoff between 20 to 35 secs, got %v", val) 25 } 26 val = backoff.nextBackoff() 27 if val < 40*time.Second || val > 55*time.Second { 28 t.Errorf("expecting backoff between 40 to 55 secs, got %v", val) 29 } 30 val = backoff.nextBackoff() 31 if val != 64*time.Second { 32 t.Errorf("expecting backoff of 64 secs, got %v", val) 33 } 34 }