context_test.go 378 B

12345678910111213141516171819202122232425
  1. package backoff
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. )
  7. func TestContext(t *testing.T) {
  8. b := NewConstantBackOff(time.Millisecond)
  9. ctx, cancel := context.WithCancel(context.Background())
  10. defer cancel()
  11. cb := WithContext(b, ctx)
  12. if cb.Context() != ctx {
  13. t.Error("invalid context")
  14. }
  15. cancel()
  16. if cb.NextBackOff() != Stop {
  17. t.Error("invalid next back off")
  18. }
  19. }