package origin import ( "context" "errors" "fmt" "testing" "time" "github.com/google/uuid" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs" ) func TestRefreshAuthBackoff(t *testing.T) { logger := logrus.New() logger.Level = logrus.ErrorLevel var wait time.Duration timeAfter = func(d time.Duration) <-chan time.Time { wait = d return time.After(d) } s, err := NewSupervisor(&TunnelConfig{Logger: logger}, uuid.New()) if !assert.NoError(t, err) { t.FailNow() } backoff := &BackoffHandler{MaxRetries: 3} auth := func(ctx context.Context, n int) (tunnelpogs.AuthOutcome, error) { return nil, fmt.Errorf("authentication failure") } // authentication failures should consume the backoff for i := uint(0); i < backoff.MaxRetries; i++ { retryChan, err := s.refreshAuth(context.Background(), backoff, auth) assert.NoError(t, err) assert.NotNil(t, retryChan) assert.Equal(t, (1<