Skip to content

Commit 118bf96

Browse files
committed
fix test
1 parent 7c3ee64 commit 118bf96

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

services/pull/check.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,18 @@ func StartPullRequestCheckOnView(ctx context.Context, pr *issues_model.PullReque
106106
// So duplicate "start" requests will be ignored if there is already a task in the queue or one is running.
107107
// Ideally in the future we should decouple the "unique queue" feature from the "start" request.
108108
if pr.Status == issues_model.PullRequestStatusChecking {
109-
// When a PR check starts, the task is popped from the queue and the task handler acquires the global lock
110-
// So we need to acquire the global lock here to prevent from duplicate tasks
111-
_, _ = globallock.TryLockAndDo(ctx, getPullWorkingLockKey(pr.ID), func(ctx context.Context) error {
112-
AddPullRequestToCheckQueue(pr.ID) // the queue is a unique queue and won't add the same task again
113-
return nil
114-
})
109+
if setting.IsInTesting {
110+
// In testing mode, there might be an "immediate" queue, which is not a real queue, everything is executed in the same goroutine
111+
// So we can't use the global lock here, otherwise it will cause a deadlock.
112+
AddPullRequestToCheckQueue(pr.ID)
113+
} else {
114+
// When a PR check starts, the task is popped from the queue and the task handler acquires the global lock
115+
// So we need to acquire the global lock here to prevent from duplicate tasks
116+
_, _ = globallock.TryLockAndDo(ctx, getPullWorkingLockKey(pr.ID), func(ctx context.Context) error {
117+
AddPullRequestToCheckQueue(pr.ID) // the queue is a unique queue and won't add the same task again
118+
return nil
119+
})
120+
}
115121
}
116122
}
117123

0 commit comments

Comments
 (0)