Skip to content

Commit cc16887

Browse files
forgejo-backport-actionearl-warren
authored andcommitted
[v12.0/forgejo] chore: fix transient error in TestPatchStatus tests (take 2) (#9243)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/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 --- Without this fix it fails 100% of the time locally on testify v1.11 because it runs the test before waiting stretchr/testify#1427 Co-authored-by: Earl Warren <[email protected]> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9243 Reviewed-by: Earl Warren <[email protected]> Co-authored-by: forgejo-backport-action <[email protected]> Co-committed-by: forgejo-backport-action <[email protected]>
1 parent e34cdca commit cc16887

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tests/integration/patch_status_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,19 @@ func TestPatchStatus(t *testing.T) {
144144
require.NoError(t, git.NewCommand(t.Context(), "push", "origin", "HEAD:main").Run(&git.RunOpts{Dir: dstPath}))
145145
require.NoError(t, git.NewCommand(t.Context(), "switch", "normal").Run(&git.RunOpts{Dir: dstPath}))
146146

147-
assertConflictAndLoadBean := func(t *testing.T, pr *issues_model.PullRequest, flow string) *issues_model.PullRequest {
147+
assertConflictAndLoadBean := func(t *testing.T, pr issues_model.PullRequest, flow string) *issues_model.PullRequest {
148148
t.Helper()
149+
var found *issues_model.PullRequest
149150
assert.Eventually(t, func() bool {
150-
return unittest.AssertExistsAndLoadBean(t, pr, flow).Status == issues_model.PullRequestStatusConflict
151+
examplar := pr
152+
found = unittest.AssertExistsAndLoadBean(t, &examplar, flow)
153+
return found.Status == issues_model.PullRequestStatusConflict
151154
}, time.Second*30, time.Millisecond*200)
152-
return pr
155+
return found
153156
}
154157
// Wait until status check queue is done, we cannot access the queue's
155158
// internal information so we rely on the status of the patch being changed.
156-
_ = assertConflictAndLoadBean(t, &issues_model.PullRequest{ID: normalAGitPR.ID}, "flow = 1")
159+
_ = assertConflictAndLoadBean(t, issues_model.PullRequest{ID: normalAGitPR.ID}, "flow = 1")
157160

158161
test := func(t *testing.T, pr *issues_model.PullRequest) {
159162
t.Helper()
@@ -170,7 +173,7 @@ func TestPatchStatus(t *testing.T) {
170173
t.Run("Existing", func(t *testing.T) {
171174
defer tests.PrintCurrentTest(t)()
172175

173-
pr := assertConflictAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "normal"}, "flow = 0")
176+
pr := assertConflictAndLoadBean(t, issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "normal"}, "flow = 0")
174177
test(t, pr)
175178
testAutomergeQueued(t, pr, issues_model.PullRequestStatusConflict)
176179
})
@@ -181,7 +184,7 @@ func TestPatchStatus(t *testing.T) {
181184
require.NoError(t, git.NewCommand(t.Context(), "push", "fork", "HEAD:conflict").Run(&git.RunOpts{Dir: dstPath}))
182185
testPullCreateDirectly(t, session, repo.OwnerName, repo.Name, repo.DefaultBranch, forkRepo.OwnerName, forkRepo.Name, "conflict", "across repo conflict")
183186

184-
test(t, assertConflictAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "conflict"}, "flow = 0"))
187+
test(t, assertConflictAndLoadBean(t, issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "conflict"}, "flow = 0"))
185188
})
186189
})
187190

0 commit comments

Comments
 (0)