MCPcopy
hub / github.com/gofiber/fiber / Benchmark_App_MethodNotAllowed_Parallel

Function Benchmark_App_MethodNotAllowed_Parallel

router_test.go:2101–2127  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

2099}
2100
2101func 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
2129func Benchmark_Router_NotFound_Parallel(b *testing.B) {
2130 b.ReportAllocs()

Callers

nothing calls this directly

Calls 11

HandlerMethod · 0.80
SetMethodMethod · 0.80
SetPathMethod · 0.80
URIMethod · 0.80
NewFunction · 0.70
SendStringMethod · 0.65
AllMethod · 0.65
GetMethod · 0.65
NextMethod · 0.65
BodyMethod · 0.65
StatusCodeMethod · 0.45

Tested by

no test coverage detected