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

Function Benchmark_Client_Request_Send_ContextCancel

client/client_test.go:2395–2439  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

2393}
2394
2395func Benchmark_Client_Request_Send_ContextCancel(b *testing.B) {
2396 app, ln, start := createHelperServer(b)
2397
2398 startedCh := make(chan struct{})
2399 errCh := make(chan error)
2400 respCh := make(chan *Response)
2401
2402 app.Post("/", func(c fiber.Ctx) error {
2403 startedCh <- struct{}{}
2404 time.Sleep(time.Millisecond) // let cancel be called
2405 return c.Status(fiber.StatusOK).SendString("post")
2406 })
2407
2408 go start()
2409
2410 client := New().SetDial(ln)
2411
2412 b.ReportAllocs()
2413 b.ResetTimer()
2414
2415 for b.Loop() {
2416 ctx, cancel := context.WithCancel(context.Background())
2417
2418 req := AcquireRequest().
2419 SetClient(client).
2420 SetURL("http://example.com").
2421 SetMethod(fiber.MethodPost).
2422 SetContext(ctx)
2423
2424 go func(r *Request) {
2425 defer ReleaseRequest(r)
2426
2427 resp, err := r.Send()
2428
2429 respCh <- resp
2430 errCh <- err
2431 }(req)
2432
2433 <-startedCh // request is made, we can cancel the context now
2434 cancel()
2435
2436 require.Nil(b, <-respCh)
2437 require.ErrorIs(b, <-errCh, ErrTimeoutOrCancel)
2438 }
2439}
2440
2441func Test_Client_StreamResponseBody(t *testing.T) {
2442 t.Parallel()

Callers

nothing calls this directly

Calls 13

createHelperServerFunction · 0.85
AcquireRequestFunction · 0.85
ReleaseRequestFunction · 0.85
SetMethodMethod · 0.80
SetURLMethod · 0.80
SetClientMethod · 0.80
NewFunction · 0.70
PostMethod · 0.65
SendStringMethod · 0.65
StatusMethod · 0.65
SetDialMethod · 0.65
SetContextMethod · 0.65

Tested by

no test coverage detected