chore: fix transient error in TestPatchStatus tests (#9236)

wait on all pull requests before checking their conflict status because there is no guarantee one will be dealt with before another

Refs https://codeberg.org/forgejo/forgejo/issues/8221#issuecomment-6849601

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9236
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-09-10 18:07:15 +02:00 committed by Earl Warren
commit 9420945daa

View file

@ -144,11 +144,16 @@ func TestPatchStatus(t *testing.T) {
require.NoError(t, git.NewCommand(t.Context(), "push", "origin", "HEAD:main").Run(&git.RunOpts{Dir: dstPath})) require.NoError(t, git.NewCommand(t.Context(), "push", "origin", "HEAD:main").Run(&git.RunOpts{Dir: dstPath}))
require.NoError(t, git.NewCommand(t.Context(), "switch", "normal").Run(&git.RunOpts{Dir: dstPath})) require.NoError(t, git.NewCommand(t.Context(), "switch", "normal").Run(&git.RunOpts{Dir: dstPath}))
assertConflictAndLoadBean := func(t *testing.T, pr *issues_model.PullRequest, flow string) *issues_model.PullRequest {
t.Helper()
assert.Eventually(t, func() bool {
return unittest.AssertExistsAndLoadBean(t, pr, flow).Status == issues_model.PullRequestStatusConflict
}, time.Second*30, time.Millisecond*200)
return pr
}
// Wait until status check queue is done, we cannot access the queue's // Wait until status check queue is done, we cannot access the queue's
// internal information so we rely on the status of the patch being changed. // internal information so we rely on the status of the patch being changed.
assert.Eventually(t, func() bool { _ = assertConflictAndLoadBean(t, &issues_model.PullRequest{ID: normalAGitPR.ID}, "flow = 1")
return unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: normalAGitPR.ID}).Status == issues_model.PullRequestStatusConflict
}, time.Second*30, time.Millisecond*200)
test := func(t *testing.T, pr *issues_model.PullRequest) { test := func(t *testing.T, pr *issues_model.PullRequest) {
t.Helper() t.Helper()
@ -165,7 +170,7 @@ func TestPatchStatus(t *testing.T) {
t.Run("Existing", func(t *testing.T) { t.Run("Existing", func(t *testing.T) {
defer tests.PrintCurrentTest(t)() defer tests.PrintCurrentTest(t)()
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "normal"}, "flow = 0") pr := assertConflictAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "normal"}, "flow = 0")
test(t, pr) test(t, pr)
testAutomergeQueued(t, pr, issues_model.PullRequestStatusConflict) testAutomergeQueued(t, pr, issues_model.PullRequestStatusConflict)
}) })
@ -176,7 +181,7 @@ func TestPatchStatus(t *testing.T) {
require.NoError(t, git.NewCommand(t.Context(), "push", "fork", "HEAD:conflict").Run(&git.RunOpts{Dir: dstPath})) require.NoError(t, git.NewCommand(t.Context(), "push", "fork", "HEAD:conflict").Run(&git.RunOpts{Dir: dstPath}))
testPullCreateDirectly(t, session, repo.OwnerName, repo.Name, repo.DefaultBranch, forkRepo.OwnerName, forkRepo.Name, "conflict", "across repo conflict") testPullCreateDirectly(t, session, repo.OwnerName, repo.Name, repo.DefaultBranch, forkRepo.OwnerName, forkRepo.Name, "conflict", "across repo conflict")
test(t, unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "conflict"}, "flow = 0")) test(t, assertConflictAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "conflict"}, "flow = 0"))
}) })
}) })