mirror of https://github.com/v2ray/v2ray-core
rename retry_test package
parent
abdcda0a2f
commit
7e481fe943
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errorRetryFailed = errors.New("All retry attempts failed.")
|
ErrorRetryFailed = errors.New("All retry attempts failed.")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Strategy is a way to retry on a specific function.
|
// Strategy is a way to retry on a specific function.
|
||||||
|
@ -29,7 +29,7 @@ func (r *retryer) On(method func() error) error {
|
||||||
}
|
}
|
||||||
delay := r.NextDelay(attempt)
|
delay := r.NextDelay(attempt)
|
||||||
if delay < 0 {
|
if delay < 0 {
|
||||||
return errorRetryFailed
|
return ErrorRetryFailed
|
||||||
}
|
}
|
||||||
<-time.After(time.Duration(delay) * time.Millisecond)
|
<-time.After(time.Duration(delay) * time.Millisecond)
|
||||||
attempt++
|
attempt++
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package retry
|
package retry_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
. "github.com/v2ray/v2ray-core/common/retry"
|
||||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||||
"github.com/v2ray/v2ray-core/testing/assert"
|
"github.com/v2ray/v2ray-core/testing/assert"
|
||||||
)
|
)
|
||||||
|
@ -76,6 +77,6 @@ func TestRetryExhausted(t *testing.T) {
|
||||||
})
|
})
|
||||||
duration := time.Since(startTime)
|
duration := time.Since(startTime)
|
||||||
|
|
||||||
assert.Error(err).Equals(errorRetryFailed)
|
assert.Error(err).Equals(ErrorRetryFailed)
|
||||||
assert.Int64(int64(duration / time.Millisecond)).AtLeast(1900)
|
assert.Int64(int64(duration / time.Millisecond)).AtLeast(1900)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue