Skip to content

Commit aab1813

Browse files
forgejo-backport-actionearl-warren
authored andcommitted
[v11.0/forgejo] chore: fix transient error in TestPatchStatus tests (take 2) (#9242)
**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/9242 Reviewed-by: Earl Warren <[email protected]> Co-authored-by: forgejo-backport-action <[email protected]> Co-committed-by: forgejo-backport-action <[email protected]>
1 parent 305e059 commit aab1813

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
@@ -140,16 +140,19 @@ func TestPatchStatus(t *testing.T) {
140140
require.NoError(t, git.NewCommand(t.Context(), "push", "origin", "HEAD:main").Run(&git.RunOpts{Dir: dstPath}))
141141
require.NoError(t, git.NewCommand(t.Context(), "switch", "normal").Run(&git.RunOpts{Dir: dstPath}))
142142

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

154157
test := func(t *testing.T, pr *issues_model.PullRequest) {
155158
t.Helper()
@@ -166,7 +169,7 @@ func TestPatchStatus(t *testing.T) {
166169
t.Run("Existing", func(t *testing.T) {
167170
defer tests.PrintCurrentTest(t)()
168171

169-
pr := assertConflictAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "normal"}, "flow = 0")
172+
pr := assertConflictAndLoadBean(t, issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "normal"}, "flow = 0")
170173
test(t, pr)
171174
testAutomergeQueued(t, pr, issues_model.PullRequestStatusConflict)
172175
})
@@ -177,7 +180,7 @@ func TestPatchStatus(t *testing.T) {
177180
require.NoError(t, git.NewCommand(t.Context(), "push", "fork", "HEAD:conflict").Run(&git.RunOpts{Dir: dstPath}))
178181
testPullCreateDirectly(t, session, repo.OwnerName, repo.Name, repo.DefaultBranch, forkRepo.OwnerName, forkRepo.Name, "conflict", "across repo conflict")
179182

180-
test(t, assertConflictAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "conflict"}, "flow = 0"))
183+
test(t, assertConflictAndLoadBean(t, issues_model.PullRequest{BaseRepoID: repo.ID, HeadRepoID: forkRepo.ID, HeadBranch: "conflict"}, "flow = 0"))
181184
})
182185
})
183186

0 commit comments

Comments
 (0)