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

Function Test_Client_LBClient_Behavior

client/client_test.go:464–651  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

462}
463
464func Test_Client_LBClient_Behavior(t *testing.T) {
465 t.Parallel()
466
467 newLBClient := func(addr string) *fasthttp.LBClient {
468 return &fasthttp.LBClient{
469 Clients: []fasthttp.BalancingClient{
470 &fasthttp.HostClient{Addr: addr},
471 },
472 }
473 }
474
475 t.Run("do and redirects", func(t *testing.T) {
476 t.Parallel()
477
478 app, addr := startTestServerWithPort(t, func(app *fiber.App) {
479 app.Get("/ok", func(c fiber.Ctx) error {
480 return c.SendString("ok")
481 })
482 app.Get("/redirect", func(c fiber.Ctx) error {
483 return c.Redirect().Status(fiber.StatusFound).To("/ok")
484 })
485 })
486 t.Cleanup(func() {
487 require.NoError(t, app.Shutdown())
488 })
489
490 client := NewWithLBClient(newLBClient(addr))
491
492 resp, err := client.Get("http://" + addr + "/ok")
493 require.NoError(t, err)
494 require.Equal(t, fiber.StatusOK, resp.StatusCode())
495 require.Equal(t, "ok", resp.String())
496
497 resp, err = client.Get("http://"+addr+"/redirect", Config{MaxRedirects: 1})
498 require.NoError(t, err)
499 require.Equal(t, fiber.StatusOK, resp.StatusCode())
500 require.Equal(t, "ok", resp.String())
501 })
502
503 t.Run("retries respect dial overrides", func(t *testing.T) {
504 t.Parallel()
505
506 app, addr := startTestServerWithPort(t, func(app *fiber.App) {
507 app.Get("/", func(c fiber.Ctx) error {
508 return c.SendString("retry")
509 })
510 })
511 t.Cleanup(func() {
512 require.NoError(t, app.Shutdown())
513 })
514
515 client := NewWithLBClient(newLBClient(addr))
516 client.SetRetryConfig(&RetryConfig{
517 InitialInterval: time.Millisecond,
518 MaxRetryCount: 2,
519 })
520
521 var attempts atomic.Int32

Callers

nothing calls this directly

Calls 15

GetTLSConfigsFunction · 0.92
startTestServerWithPortFunction · 0.85
NewWithLBClientFunction · 0.85
ToMethod · 0.80
ShutdownMethod · 0.80
SetRetryConfigMethod · 0.80
ListenMethod · 0.80
ListenerMethod · 0.80
AddrMethod · 0.80
SetProxyURLMethod · 0.80
FasthttpClientMethod · 0.80
HostClientMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…