From f5eef7ec01ceae3279b7031b3a94e3f889b6e087 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 18 Apr 2024 10:50:58 +0800 Subject: [PATCH] fix --- modules/queue/backoff.go | 10 +++++++++- modules/queue/workerqueue_test.go | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/queue/backoff.go b/modules/queue/backoff.go index cda7233567d7..02fc88574a60 100644 --- a/modules/queue/backoff.go +++ b/modules/queue/backoff.go @@ -8,7 +8,7 @@ import ( "time" ) -const ( +var ( backoffBegin = 50 * time.Millisecond backoffUpper = 2 * time.Second ) @@ -18,6 +18,14 @@ type ( 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) { d := begin for { diff --git a/modules/queue/workerqueue_test.go b/modules/queue/workerqueue_test.go index e09669c54255..a08b02a123bc 100644 --- a/modules/queue/workerqueue_test.go +++ b/modules/queue/workerqueue_test.go @@ -250,6 +250,7 @@ func TestWorkerPoolQueueShutdown(t *testing.T) { func TestWorkerPoolQueueWorkerIdleReset(t *testing.T) { defer test.MockVariableValue(&workerIdleDuration, 10*time.Millisecond)() + defer mockBackoffDuration(10 * time.Millisecond)() handler := func(items ...int) (unhandled []int) { time.Sleep(50 * time.Millisecond)