From 46bcf4efc071dba5a08e5187cd36ad77ca0de87a Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 10 Sep 2025 20:48:46 +0200 Subject: [PATCH] chore: fix transient error in TestPatchStatus tests (take 2) (#9241) AssertExistsAndLoadBean has a side effect on its argument. When retrying in a loop, it must use the non modified argument, otherwise it is bound to return the same row as the first failure and render the retry useless. Refs forgejo/forgejo#9236 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9241 Reviewed-by: Gusted Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- tests/integration/patch_status_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/integration/patch_status_test.go b/tests/integration/patch_status_test.go index ac41860641..c54cad91c4 100644 --- a/tests/integration/patch_status_test.go +++ b/tests/integration/patch_status_test.go @@ -144,16 +144,19 @@ 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(), "switch", "normal").Run(&git.RunOpts{Dir: dstPath})) - assertConflictAndLoadBean := func(t *testing.T, pr *issues_model.PullRequest, flow string) *issues_model.PullRequest { + assertConflictAndLoadBean := func(t *testing.T, pr issues_model.PullRequest, flow string) *issues_model.PullRequest { t.Helper() + var found *issues_model.PullRequest assert.Eventually(t, func() bool { - return unittest.AssertExistsAndLoadBean(t, pr, flow).Status == issues_model.PullRequestStatusConflict + examplar := pr + found = unittest.AssertExistsAndLoadBean(t, &examplar, flow) + return found.Status == issues_model.PullRequestStatusConflict }, time.Second*30, time.Millisecond*200) - return pr + return found } // 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. - _ = assertConflictAndLoadBean(t, &issues_model.PullRequest{ID: normalAGitPR.ID}, "flow = 1") + _ = assertConflictAndLoadBean(t, issues_model.PullRequest{ID: normalAGitPR.ID}, "flow = 1") test := func(t *testing.T, pr *issues_model.PullRequest) { t.Helper() @@ -170,7 +173,7 @@ func TestPatchStatus(t *testing.T) { t.Run("Existing", func(t *testing.T) { defer tests.PrintCurrentTest(t)() - pr := assertConflictAndLoadBean(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) testAutomergeQueued(t, pr, issues_model.PullRequestStatusConflict) }) @@ -181,7 +184,7 @@ func TestPatchStatus(t *testing.T) { 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") - test(t, assertConflictAndLoadBean(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")) }) })