mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-11-30 21:35:27 +00:00
1e4dfe2ae8
Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/66 Reviewed-by: Otto Richter <otto@codeberg.org>
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
"codeberg.org/codeberg/pages/server/cache"
|
|
)
|
|
|
|
func TestHandlerPerformance(t *testing.T) {
|
|
testHandler := Handler(
|
|
[]byte("codeberg.page"),
|
|
[]byte("raw.codeberg.org"),
|
|
"https://codeberg.org",
|
|
"https://docs.codeberg.org/pages/raw-content/",
|
|
"",
|
|
[][]byte{[]byte("/.well-known/acme-challenge/")},
|
|
[][]byte{[]byte("raw.codeberg.org"), []byte("fonts.codeberg.org"), []byte("design.codeberg.org")},
|
|
cache.NewKeyValueCache(),
|
|
cache.NewKeyValueCache(),
|
|
cache.NewKeyValueCache(),
|
|
cache.NewKeyValueCache(),
|
|
)
|
|
|
|
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())
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|