(b *testing.B)
| 2393 | } |
| 2394 | |
| 2395 | func 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 | |
| 2441 | func Test_Client_StreamResponseBody(t *testing.T) { |
| 2442 | t.Parallel() |
nothing calls this directly
no test coverage detected