Add timing tests

This commit is contained in:
Moritz Marquardt 2021-07-08 23:08:58 +02:00
parent 3e9aaa8a4a
commit f63bd1bb2f
No known key found for this signature in database
GPG Key ID: D5788327BEE388B6
1 changed files with 39 additions and 0 deletions

39
handler_test.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"fmt"
"github.com/valyala/fasthttp"
"testing"
"time"
)
func TestHandlerPerformance(t *testing.T) {
ctx := &fasthttp.RequestCtx{
Request: *fasthttp.AcquireRequest(),
Response: *fasthttp.AcquireResponse(),
}
ctx.Request.SetRequestURI("http://mondstern.codeberg:8080/")
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()) < 2048 {
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())
}
ctx.Response.Reset()
ctx.Response.ResetBody()
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()) < 2048 {
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())
}
}