Add timing tests & fix caching

This commit is contained in:
Moritz Marquardt 2021-07-13 10:28:06 +02:00
parent 675e56ee98
commit 0602811709
No known key found for this signature in database
GPG key ID: D5788327BEE388B6
4 changed files with 166 additions and 29 deletions

View file

@ -12,7 +12,7 @@ func TestHandlerPerformance(t *testing.T) {
Request: *fasthttp.AcquireRequest(),
Response: *fasthttp.AcquireResponse(),
}
ctx.Request.SetRequestURI("http://mondstern.codeberg:8080/")
ctx.Request.SetRequestURI("http://mondstern.codeberg.page/")
fmt.Printf("Start: %v\n", time.Now())
start := time.Now()
handler(ctx)
@ -36,4 +36,19 @@ func TestHandlerPerformance(t *testing.T) {
} else {
t.Logf("request took %d milliseconds", end.Sub(start).Milliseconds())
}
ctx.Response.Reset()
ctx.Response.ResetBody()
ctx.Request.SetRequestURI("http://example.momar.xyz/")
fmt.Printf("Start: %v\n", time.Now())
start = time.Now()
handler(ctx)
end = time.Now()
fmt.Printf("Done: %v\n", time.Now())
if ctx.Response.StatusCode() != 200 || len(ctx.Response.Body()) < 1 {
t.Errorf("request failed with status code %d and body length %d", ctx.Response.StatusCode(), len(ctx.Response.Body()))
} else {
t.Logf("request took %d milliseconds", end.Sub(start).Milliseconds())
}
}