aboutsummaryrefslogtreecommitdiffstats
path: root/integrations/integration_test.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-04-06 17:44:02 +0100
committerGitHub <noreply@github.com>2021-04-06 18:44:02 +0200
commit8be2cc4fc72e7985640dabdddb06cf78169c1882 (patch)
treefe3b6467911a615637d33d07020361a981016e6b /integrations/integration_test.go
parentb101fa83a6d75922d079e2b7e0437a123a90bb62 (diff)
downloadgitea-8be2cc4fc72e7985640dabdddb06cf78169c1882.tar.gz
gitea-8be2cc4fc72e7985640dabdddb06cf78169c1882.zip
Reduce memory usage in testgit (#15306)
* reduce memory use in rawtest * just use hashsum for diffs Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'integrations/integration_test.go')
-rw-r--r--integrations/integration_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index 10331a1560..74227416c4 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -9,6 +9,8 @@ import (
"context"
"database/sql"
"fmt"
+ "hash"
+ "hash/fnv"
"io"
"net/http"
"net/http/cookiejar"
@@ -58,6 +60,26 @@ func NewNilResponseRecorder() *NilResponseRecorder {
}
}
+type NilResponseHashSumRecorder struct {
+ httptest.ResponseRecorder
+ Hash hash.Hash
+ Length int
+}
+
+func (n *NilResponseHashSumRecorder) Write(b []byte) (int, error) {
+ _, _ = n.Hash.Write(b)
+ n.Length += len(b)
+ return len(b), nil
+}
+
+// NewRecorder returns an initialized ResponseRecorder.
+func NewNilResponseHashSumRecorder() *NilResponseHashSumRecorder {
+ return &NilResponseHashSumRecorder{
+ Hash: fnv.New32(),
+ ResponseRecorder: *httptest.NewRecorder(),
+ }
+}
+
func TestMain(m *testing.M) {
defer log.Close()
@@ -284,6 +306,23 @@ func (s *TestSession) MakeRequestNilResponseRecorder(t testing.TB, req *http.Req
return resp
}
+func (s *TestSession) MakeRequestNilResponseHashSumRecorder(t testing.TB, req *http.Request, expectedStatus int) *NilResponseHashSumRecorder {
+ t.Helper()
+ baseURL, err := url.Parse(setting.AppURL)
+ assert.NoError(t, err)
+ for _, c := range s.jar.Cookies(baseURL) {
+ req.AddCookie(c)
+ }
+ resp := MakeRequestNilResponseHashSumRecorder(t, req, expectedStatus)
+
+ ch := http.Header{}
+ ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";"))
+ cr := http.Request{Header: ch}
+ s.jar.SetCookies(baseURL, cr.Cookies())
+
+ return resp
+}
+
const userPassword = "password"
var loginSessionCache = make(map[string]*TestSession, 10)
@@ -429,6 +468,19 @@ func MakeRequestNilResponseRecorder(t testing.TB, req *http.Request, expectedSta
return recorder
}
+func MakeRequestNilResponseHashSumRecorder(t testing.TB, req *http.Request, expectedStatus int) *NilResponseHashSumRecorder {
+ t.Helper()
+ recorder := NewNilResponseHashSumRecorder()
+ c.ServeHTTP(recorder, req)
+ if expectedStatus != NoExpectedStatus {
+ if !assert.EqualValues(t, expectedStatus, recorder.Code,
+ "Request: %s %s", req.Method, req.URL.String()) {
+ logUnexpectedResponse(t, &recorder.ResponseRecorder)
+ }
+ }
+ return recorder
+}
+
// logUnexpectedResponse logs the contents of an unexpected response.
func logUnexpectedResponse(t testing.TB, recorder *httptest.ResponseRecorder) {
t.Helper()