github.com/cenkalti/backoff/v4@v4.2.1/context_test.go (about) 1 package backoff 2 3 import ( 4 "context" 5 "testing" 6 "time" 7 ) 8 9 func TestContext(t *testing.T) { 10 b := NewConstantBackOff(time.Millisecond) 11 ctx, cancel := context.WithCancel(context.Background()) 12 defer cancel() 13 14 cb := WithContext(b, ctx) 15 16 if cb.Context() != ctx { 17 t.Error("invalid context") 18 } 19 20 cancel() 21 22 if cb.NextBackOff() != Stop { 23 t.Error("invalid next back off") 24 } 25 }