mirror of
https://github.com/go-gitea/gitea
synced 2024-11-25 14:02:58 +01:00
Mock queue backoff duration (#30553)
During testing, the backoff duration shouldn't be longer than other durations
This commit is contained in:
parent
dd8e6ae270
commit
bcbeb24dba
2 changed files with 10 additions and 1 deletions
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
var (
|
||||||
backoffBegin = 50 * time.Millisecond
|
backoffBegin = 50 * time.Millisecond
|
||||||
backoffUpper = 2 * time.Second
|
backoffUpper = 2 * time.Second
|
||||||
)
|
)
|
||||||
|
@ -18,6 +18,14 @@ type (
|
||||||
backoffFuncErr func() (retry bool, err error)
|
backoffFuncErr func() (retry bool, err error)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func mockBackoffDuration(d time.Duration) func() {
|
||||||
|
oldBegin, oldUpper := backoffBegin, backoffUpper
|
||||||
|
backoffBegin, backoffUpper = d, d
|
||||||
|
return func() {
|
||||||
|
backoffBegin, backoffUpper = oldBegin, oldUpper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func backoffRetErr[T any](ctx context.Context, begin, upper time.Duration, end <-chan time.Time, fn backoffFuncRetErr[T]) (ret T, err error) {
|
func backoffRetErr[T any](ctx context.Context, begin, upper time.Duration, end <-chan time.Time, fn backoffFuncRetErr[T]) (ret T, err error) {
|
||||||
d := begin
|
d := begin
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -250,6 +250,7 @@ func TestWorkerPoolQueueShutdown(t *testing.T) {
|
||||||
|
|
||||||
func TestWorkerPoolQueueWorkerIdleReset(t *testing.T) {
|
func TestWorkerPoolQueueWorkerIdleReset(t *testing.T) {
|
||||||
defer test.MockVariableValue(&workerIdleDuration, 10*time.Millisecond)()
|
defer test.MockVariableValue(&workerIdleDuration, 10*time.Millisecond)()
|
||||||
|
defer mockBackoffDuration(10 * time.Millisecond)()
|
||||||
|
|
||||||
handler := func(items ...int) (unhandled []int) {
|
handler := func(items ...int) (unhandled []int) {
|
||||||
time.Sleep(50 * time.Millisecond)
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
|
Loading…
Reference in a new issue