Skip to content

Commit 2ad74a5

Browse files
authored
Attempt to prevent intermittent failure TestGit/xxx/BranchProtectMerge/MergePR (#18451)
One of the repeated intermittent failures we see in testing is a failure due to branches not being ready to merge. Prior to the immediate queue implementation we would attempt to flush all the queues and this would prevent the issue. However, the immediate queue is not flushable so the flushall is not successful at preventing this. This PR proposes an alternative solution - wait some time and try again up to 5 times. If this fails then there is a genuine issue and we should fail. Related #17719 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent b34923d commit 2ad74a5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

integrations/api_helper_for_declarative_test.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"net/http"
11+
"net/http/httptest"
1112
"net/url"
1213
"os"
1314
"testing"
@@ -262,23 +263,26 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
262263
return func(t *testing.T) {
263264
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge?token=%s",
264265
owner, repo, index, ctx.Token)
265-
req := NewRequestWithJSON(t, http.MethodPost, urlStr, &forms.MergePullRequestForm{
266-
MergeMessageField: "doAPIMergePullRequest Merge",
267-
Do: string(repo_model.MergeStyleMerge),
268-
})
269266

270-
resp := ctx.Session.MakeRequest(t, req, NoExpectedStatus)
267+
var req *http.Request
268+
var resp *httptest.ResponseRecorder
271269

272-
if resp.Code == http.StatusMethodNotAllowed {
273-
err := api.APIError{}
274-
DecodeJSON(t, resp, &err)
275-
assert.EqualValues(t, "Please try again later", err.Message)
276-
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
270+
for i := 0; i < 6; i++ {
277271
req = NewRequestWithJSON(t, http.MethodPost, urlStr, &forms.MergePullRequestForm{
278272
MergeMessageField: "doAPIMergePullRequest Merge",
279273
Do: string(repo_model.MergeStyleMerge),
280274
})
275+
281276
resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus)
277+
278+
if resp.Code != http.StatusMethodNotAllowed {
279+
break
280+
}
281+
err := api.APIError{}
282+
DecodeJSON(t, resp, &err)
283+
assert.EqualValues(t, "Please try again later", err.Message)
284+
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
285+
<-time.After(1 * time.Second)
282286
}
283287

284288
expected := ctx.ExpectedCode

0 commit comments

Comments
 (0)