timeout_test.go — fiber Source File
Architecture documentation for timeout_test.go, a go file in the fiber codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR bab1b67e_4e42_cfe9_38ec_3f1f6a839718["timeout_test.go"] cc7104af_aece_1fe5_3985_791c7f34910c["context"] bab1b67e_4e42_cfe9_38ec_3f1f6a839718 --> cc7104af_aece_1fe5_3985_791c7f34910c style bab1b67e_4e42_cfe9_38ec_3f1f6a839718 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
package timeout
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/valyala/fasthttp"
"github.com/gofiber/fiber/v3"
)
var (
// Custom error that we treat like a timeout when returned by the handler.
errCustomTimeout = errors.New("custom timeout error")
// Some unrelated error that should NOT trigger a request timeout.
errUnrelated = errors.New("unmatched error")
)
// sleepWithContext simulates a task that takes `d` time, but returns `te` if the context is canceled.
func sleepWithContext(ctx context.Context, d time.Duration, te error) error {
timer := time.NewTimer(d)
defer timer.Stop() // Clean up the timer
select {
case <-ctx.Done():
return te
case <-timer.C:
return nil
}
}
// TestTimeout_Success tests a handler that completes within the allotted timeout.
func TestTimeout_Success(t *testing.T) {
t.Parallel()
app := fiber.New()
// Our middleware wraps a handler that sleeps for 10ms, well under the 50ms limit.
app.Get("/fast", New(func(c fiber.Ctx) error {
// Simulate some work
if err := sleepWithContext(c.Context(), 10*time.Millisecond, context.DeadlineExceeded); err != nil {
return err
}
return c.SendString("OK")
}, Config{Timeout: 50 * time.Millisecond}))
req := httptest.NewRequest(fiber.MethodGet, "/fast", http.NoBody)
resp, err := app.Test(req)
require.NoError(t, err, "app.Test(req) should not fail")
require.Equal(t, fiber.StatusOK, resp.StatusCode, "Expected 200 OK for fast requests")
}
// ... (384 more lines)
Domain
Subdomains
Functions
- TestIsTimeoutError_CustomErrors()
- TestIsTimeoutError_DeadlineExceeded()
- TestIsTimeoutError_WithOnTimeout()
- TestTimeout_AbandonMechanism()
- TestTimeout_ContextCleanup()
- TestTimeout_ContextPropagation()
- TestTimeout_CustomError()
- TestTimeout_CustomHandler()
- TestTimeout_Exceeded()
- TestTimeout_HandlerReturnsEarlyOnCancel()
- TestTimeout_ImmediateReturn()
- TestTimeout_NegativeDuration()
- TestTimeout_Next()
- TestTimeout_PanicAfterTimeout()
- TestTimeout_PanicInHandler()
- TestTimeout_Success()
- TestTimeout_UnmatchedError()
- TestTimeout_ZeroDuration()
- sleepWithContext()
Dependencies
- context
Source
Frequently Asked Questions
What does timeout_test.go do?
timeout_test.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Adapters subdomain.
What functions are defined in timeout_test.go?
timeout_test.go defines 19 function(s): TestIsTimeoutError_CustomErrors, TestIsTimeoutError_DeadlineExceeded, TestIsTimeoutError_WithOnTimeout, TestTimeout_AbandonMechanism, TestTimeout_ContextCleanup, TestTimeout_ContextPropagation, TestTimeout_CustomError, TestTimeout_CustomHandler, TestTimeout_Exceeded, TestTimeout_HandlerReturnsEarlyOnCancel, and 9 more.
What does timeout_test.go depend on?
timeout_test.go imports 1 module(s): context.
Where is timeout_test.go in the architecture?
timeout_test.go is located at middleware/timeout/timeout_test.go (domain: FiberCore, subdomain: Adapters, directory: middleware/timeout).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free