Skip to content

Commit af31f16

Browse files
committed
Attempt to handle unready PR in tests (go-gitea#13305)
Backport go-gitea#13305 Signed-off-by: Andrew Thornton <[email protected]>
1 parent f1fd8a7 commit af31f16

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

integrations/api_helper_for_declarative_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
package integrations
66

77
import (
8+
"context"
89
"encoding/json"
910
"fmt"
1011
"io/ioutil"
1112
"net/http"
1213
"testing"
14+
"time"
1315

1416
"code.gitea.io/gitea/models"
1517
"code.gitea.io/gitea/modules/auth"
18+
"code.gitea.io/gitea/modules/queue"
1619
api "code.gitea.io/gitea/modules/structs"
1720

1821
"github.com/stretchr/testify/assert"
@@ -224,11 +227,25 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
224227
Do: string(models.MergeStyleMerge),
225228
})
226229

227-
if ctx.ExpectedCode != 0 {
228-
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)
229-
return
230+
resp := ctx.Session.MakeRequest(t, req, NoExpectedStatus)
231+
232+
if resp.Code == http.StatusMethodNotAllowed {
233+
err := api.APIError{}
234+
DecodeJSON(t, resp, &err)
235+
assert.EqualValues(t, "Please try again later", err.Message)
236+
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
237+
resp = ctx.Session.MakeRequest(t, req, NoExpectedStatus)
238+
}
239+
240+
expected := ctx.ExpectedCode
241+
if expected == 0 {
242+
expected = 200
243+
}
244+
245+
if !assert.EqualValues(t, expected, resp.Code,
246+
"Request: %s %s", req.Method, req.URL.String()) {
247+
logUnexpectedResponse(t, resp)
230248
}
231-
ctx.Session.MakeRequest(t, req, 200)
232249
}
233250
}
234251

0 commit comments

Comments
 (0)