Skip to content

Commit 66dcf10

Browse files
authored
Attempt to handle unready PR in tests (#13305)
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 7974b34 commit 66dcf10

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"
@@ -225,11 +228,25 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)
225228
Do: string(models.MergeStyleMerge),
226229
})
227230

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

0 commit comments

Comments
 (0)