2022-11-12 19:43:44 +00:00
|
|
|
package handler
|
2021-07-08 21:08:58 +00:00
|
|
|
|
|
|
|
import (
|
2023-07-17 19:44:58 +00:00
|
|
|
"net/http"
|
2022-11-12 19:37:20 +00:00
|
|
|
"net/http/httptest"
|
2021-07-08 21:08:58 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
2021-12-05 14:02:44 +00:00
|
|
|
|
2024-02-15 16:08:29 +00:00
|
|
|
"codeberg.org/codeberg/pages/config"
|
2021-12-05 14:02:44 +00:00
|
|
|
"codeberg.org/codeberg/pages/server/cache"
|
2022-06-11 21:02:06 +00:00
|
|
|
"codeberg.org/codeberg/pages/server/gitea"
|
2022-11-12 19:37:20 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2021-07-08 21:08:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHandlerPerformance(t *testing.T) {
|
2024-05-26 14:45:03 +00:00
|
|
|
cfg := config.ForgeConfig{
|
2024-02-15 16:08:29 +00:00
|
|
|
Root: "https://codeberg.org",
|
|
|
|
Token: "",
|
|
|
|
LFSEnabled: false,
|
|
|
|
FollowSymlinks: false,
|
|
|
|
}
|
|
|
|
giteaClient, _ := gitea.NewClient(cfg, cache.NewInMemoryCache())
|
|
|
|
serverCfg := config.ServerConfig{
|
|
|
|
MainDomain: "codeberg.page",
|
|
|
|
RawDomain: "raw.codeberg.page",
|
|
|
|
BlacklistedPaths: []string{
|
|
|
|
"/.well-known/acme-challenge/",
|
|
|
|
},
|
|
|
|
AllowedCorsDomains: []string{"raw.codeberg.org", "fonts.codeberg.org", "design.codeberg.org"},
|
|
|
|
PagesBranches: []string{"pages"},
|
|
|
|
}
|
|
|
|
testHandler := Handler(serverCfg, giteaClient, cache.NewInMemoryCache(), cache.NewInMemoryCache(), cache.NewInMemoryCache())
|
2021-12-05 13:45:17 +00:00
|
|
|
|
2022-03-30 19:31:09 +00:00
|
|
|
testCase := func(uri string, status int) {
|
2022-11-22 21:26:10 +00:00
|
|
|
t.Run(uri, func(t *testing.T) {
|
2023-07-17 19:44:58 +00:00
|
|
|
req := httptest.NewRequest("GET", uri, http.NoBody)
|
2022-11-22 21:26:10 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
log.Printf("Start: %v\n", time.Now())
|
|
|
|
start := time.Now()
|
|
|
|
testHandler(w, req)
|
|
|
|
end := time.Now()
|
|
|
|
log.Printf("Done: %v\n", time.Now())
|
|
|
|
|
|
|
|
resp := w.Result()
|
|
|
|
|
|
|
|
if resp.StatusCode != status {
|
|
|
|
t.Errorf("request failed with status code %d", resp.StatusCode)
|
|
|
|
} else {
|
|
|
|
t.Logf("request took %d milliseconds", end.Sub(start).Milliseconds())
|
|
|
|
}
|
|
|
|
})
|
2021-07-08 21:08:58 +00:00
|
|
|
}
|
2021-07-13 08:28:06 +00:00
|
|
|
|
2022-11-22 21:26:10 +00:00
|
|
|
testCase("https://mondstern.codeberg.page/", 404) // TODO: expect 200
|
|
|
|
testCase("https://codeberg.page/", 404) // TODO: expect 200
|
|
|
|
testCase("https://example.momar.xyz/", 424)
|
2021-07-08 21:08:58 +00:00
|
|
|
}
|