diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-04-19 04:00:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 20:00:59 +0000 |
commit | bcbeb24dbaaafd79c45792a2fe020c98a246b0a7 (patch) | |
tree | 6df90c5ce584031a2879125883ed50d1c016402b /modules/queue | |
parent | dd8e6ae270b4b5e91a152a145978029dacb938ff (diff) | |
download | gitea-bcbeb24dbaaafd79c45792a2fe020c98a246b0a7.tar.gz gitea-bcbeb24dbaaafd79c45792a2fe020c98a246b0a7.zip |
Mock queue backoff duration (#30553)
During testing, the backoff duration shouldn't be longer than other
durations
Diffstat (limited to 'modules/queue')
-rw-r--r-- | modules/queue/backoff.go | 10 | ||||
-rw-r--r-- | modules/queue/workerqueue_test.go | 1 |
2 files changed, 10 insertions, 1 deletions
diff --git a/modules/queue/backoff.go b/modules/queue/backoff.go index cda7233567..02fc88574a 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 e09669c542..a08b02a123 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) |