Home / Function/ TestTimeout_CustomHandler() — fiber Function Reference

TestTimeout_CustomHandler() — fiber Function Reference

Architecture documentation for the TestTimeout_CustomHandler() function in timeout_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  11a6e143_7809_b071_6867_b0007716385b["TestTimeout_CustomHandler()"]
  bab1b67e_4e42_cfe9_38ec_3f1f6a839718["timeout_test.go"]
  11a6e143_7809_b071_6867_b0007716385b -->|defined in| bab1b67e_4e42_cfe9_38ec_3f1f6a839718
  427ca03d_9855_302a_6cda_36c7210f3310["sleepWithContext()"]
  11a6e143_7809_b071_6867_b0007716385b -->|calls| 427ca03d_9855_302a_6cda_36c7210f3310
  style 11a6e143_7809_b071_6867_b0007716385b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/timeout/timeout_test.go lines 215–242

func TestTimeout_CustomHandler(t *testing.T) {
	t.Parallel()
	app := fiber.New()
	var called atomic.Int32

	app.Get("/custom-handler", New(func(c fiber.Ctx) error {
		if err := sleepWithContext(c.Context(), 100*time.Millisecond, context.DeadlineExceeded); err != nil {
			return err
		}
		return c.SendString("should not reach")
	}, Config{
		Timeout: 20 * time.Millisecond,
		OnTimeout: func(c fiber.Ctx) error {
			called.Add(1)
			return c.Status(408).JSON(fiber.Map{"error": "timeout"})
		},
	}))

	req := httptest.NewRequest(fiber.MethodGet, "/custom-handler", http.NoBody)
	resp, err := app.Test(req)
	require.NoError(t, err)
	require.Equal(t, fiber.StatusRequestTimeout, resp.StatusCode)
	require.Equal(t, int32(1), called.Load())

	body, readErr := io.ReadAll(resp.Body)
	require.NoError(t, readErr)
	require.JSONEq(t, `{"error":"timeout"}`, string(body))
}

Domain

Subdomains

Frequently Asked Questions

What does TestTimeout_CustomHandler() do?
TestTimeout_CustomHandler() is a function in the fiber codebase, defined in middleware/timeout/timeout_test.go.
Where is TestTimeout_CustomHandler() defined?
TestTimeout_CustomHandler() is defined in middleware/timeout/timeout_test.go at line 215.
What does TestTimeout_CustomHandler() call?
TestTimeout_CustomHandler() calls 1 function(s): sleepWithContext.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free