2021-12-05 13:45:17 +00:00
|
|
|
package server
|
2021-07-08 21:08:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2021-12-05 14:02:44 +00:00
|
|
|
|
2022-03-27 19:54:06 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
|
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"
|
2021-07-08 21:08:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHandlerPerformance(t *testing.T) {
|
2022-06-11 21:02:06 +00:00
|
|
|
giteaRoot := "https://codeberg.org"
|
2022-08-12 04:40:12 +00:00
|
|
|
giteaClient, _ := gitea.NewClient(giteaRoot, "", false, false)
|
2021-12-05 13:45:17 +00:00
|
|
|
testHandler := Handler(
|
2022-06-11 21:02:06 +00:00
|
|
|
[]byte("codeberg.page"), []byte("raw.codeberg.org"),
|
|
|
|
giteaClient,
|
|
|
|
giteaRoot, "https://docs.codeberg.org/pages/raw-content/",
|
2021-12-05 13:45:17 +00:00
|
|
|
[][]byte{[]byte("/.well-known/acme-challenge/")},
|
|
|
|
[][]byte{[]byte("raw.codeberg.org"), []byte("fonts.codeberg.org"), []byte("design.codeberg.org")},
|
2021-12-05 14:02:44 +00:00
|
|
|
cache.NewKeyValueCache(),
|
|
|
|
cache.NewKeyValueCache(),
|
2021-12-05 14:53:46 +00:00
|
|
|
cache.NewKeyValueCache(),
|
|
|
|
cache.NewKeyValueCache(),
|
2021-12-05 13:45:17 +00:00
|
|
|
)
|
|
|
|
|
2022-03-30 19:31:09 +00:00
|
|
|
testCase := func(uri string, status int) {
|
|
|
|
ctx := &fasthttp.RequestCtx{
|
|
|
|
Request: *fasthttp.AcquireRequest(),
|
|
|
|
Response: *fasthttp.AcquireResponse(),
|
|
|
|
}
|
|
|
|
ctx.Request.SetRequestURI(uri)
|
|
|
|
fmt.Printf("Start: %v\n", time.Now())
|
|
|
|
start := time.Now()
|
|
|
|
testHandler(ctx)
|
|
|
|
end := time.Now()
|
|
|
|
fmt.Printf("Done: %v\n", time.Now())
|
|
|
|
if ctx.Response.StatusCode() != status {
|
|
|
|
t.Errorf("request failed with status code %d", ctx.Response.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-03-30 19:31:09 +00:00
|
|
|
testCase("https://mondstern.codeberg.page/", 424) // TODO: expect 200
|
|
|
|
testCase("https://mondstern.codeberg.page/", 424) // TODO: expect 200
|
|
|
|
testCase("https://example.momar.xyz/", 424) // TODO: expect 200
|
|
|
|
testCase("https://codeberg.page/", 424) // TODO: expect 200
|
2021-07-08 21:08:58 +00:00
|
|
|
}
|