| 2099 | } |
| 2100 | |
| 2101 | func Benchmark_App_MethodNotAllowed_Parallel(b *testing.B) { |
| 2102 | app := New() |
| 2103 | h := func(c Ctx) error { |
| 2104 | return c.SendString("Hello World!") |
| 2105 | } |
| 2106 | app.All("/this/is/a/", h) |
| 2107 | app.Get("/this/is/a/dummy/route/oke", h) |
| 2108 | appHandler := app.Handler() |
| 2109 | b.RunParallel(func(pb *testing.PB) { |
| 2110 | // Each worker gets its own RequestCtx to avoid data races |
| 2111 | c := &fasthttp.RequestCtx{} |
| 2112 | c.Request.Header.SetMethod("DELETE") |
| 2113 | c.URI().SetPath("/this/is/a/dummy/route/oke") |
| 2114 | for pb.Next() { |
| 2115 | appHandler(c) |
| 2116 | } |
| 2117 | }) |
| 2118 | |
| 2119 | // Single-threaded verification on a fresh context to preserve correctness checks |
| 2120 | verifyCtx := &fasthttp.RequestCtx{} |
| 2121 | verifyCtx.Request.Header.SetMethod("DELETE") |
| 2122 | verifyCtx.URI().SetPath("/this/is/a/dummy/route/oke") |
| 2123 | appHandler(verifyCtx) |
| 2124 | require.Equal(b, 405, verifyCtx.Response.StatusCode()) |
| 2125 | require.Equal(b, MethodGet+", "+MethodHead, string(verifyCtx.Response.Header.Peek("Allow"))) |
| 2126 | require.Equal(b, utils.StatusMessage(StatusMethodNotAllowed), string(verifyCtx.Response.Body())) |
| 2127 | } |
| 2128 | |
| 2129 | func Benchmark_Router_NotFound_Parallel(b *testing.B) { |
| 2130 | b.ReportAllocs() |