github.com/cenkalti/backoff/v4@v4.2.1/backoff_test.go (about)

     1  package backoff
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestNextBackOffMillis(t *testing.T) {
     9  	subtestNextBackOff(t, 0, new(ZeroBackOff))
    10  	subtestNextBackOff(t, Stop, new(StopBackOff))
    11  }
    12  
    13  func subtestNextBackOff(t *testing.T, expectedValue time.Duration, backOffPolicy BackOff) {
    14  	for i := 0; i < 10; i++ {
    15  		next := backOffPolicy.NextBackOff()
    16  		if next != expectedValue {
    17  			t.Errorf("got: %d expected: %d", next, expectedValue)
    18  		}
    19  	}
    20  }
    21  
    22  func TestConstantBackOff(t *testing.T) {
    23  	backoff := NewConstantBackOff(time.Second)
    24  	if backoff.NextBackOff() != time.Second {
    25  		t.Error("invalid interval")
    26  	}
    27  }