Codebase list golang-github-cenkalti-backoff / 44f23c04-7ef5-42b9-b25f-3a0726cd6cd5/main context_test.go
44f23c04-7ef5-42b9-b25f-3a0726cd6cd5/main

Tree @44f23c04-7ef5-42b9-b25f-3a0726cd6cd5/main (Download .tar.gz)

context_test.go @44f23c04-7ef5-42b9-b25f-3a0726cd6cd5/mainraw · history · blame

package backoff

import (
	"context"
	"testing"
	"time"
)

func TestContext(t *testing.T) {
	b := NewConstantBackOff(time.Millisecond)
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	cb := WithContext(b, ctx)

	if cb.Context() != ctx {
		t.Error("invalid context")
	}

	cancel()

	if cb.NextBackOff() != Stop {
		t.Error("invalid next back off")
	}
}