Test_Ctx_Value_InGoroutine() — fiber Function Reference
Architecture documentation for the Test_Ctx_Value_InGoroutine() function in ctx_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 09d70314_edf2_ff5c_7d2a_4b63e4cd5cdd["Test_Ctx_Value_InGoroutine()"] 7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"] 09d70314_edf2_ff5c_7d2a_4b63e4cd5cdd -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026 style 09d70314_edf2_ff5c_7d2a_4b63e4cd5cdd fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
ctx_test.go lines 3314–3368
func Test_Ctx_Value_InGoroutine(t *testing.T) {
t.Parallel()
app := New()
done := make(chan bool, 1) // Buffered to prevent goroutine leak
errCh := make(chan error, 1) // Channel to communicate errors from goroutine
// Use a synchronization point to avoid race detector complaints
// while still testing the defensive nil behavior
start := make(chan struct{})
app.Get("/test", func(c Ctx) error {
c.Locals("test", "value")
// Simulate a goroutine that uses the context (like minio.GetObject)
go func() {
// Wait for handler to complete and context to be released
<-start
defer func() {
if r := recover(); r != nil {
errCh <- fmt.Errorf("panic in goroutine: %v", r)
return
}
done <- true
}()
// This simulates what happens when minio or other libraries
// use the fiber.Ctx as a context.Context in a goroutine
// The Value method should not panic even if fasthttp is nil
val := c.Value("test")
// The value might be nil if the context was released
_ = val
}()
return nil
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/test", http.NoBody))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, StatusOK, resp.StatusCode, "Status code")
// Signal goroutine to proceed - context has been released after app.Test returns
// since the handler (and its deferred ReleaseCtx) has completed
close(start)
// Wait for goroutine to complete with timeout
select {
case <-done:
// Success - goroutine completed without panic
case err := <-errCh:
t.Fatalf("error from goroutine: %v", err)
case <-time.After(1 * time.Second):
t.Fatal("test timed out waiting for goroutine")
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_Ctx_Value_InGoroutine() do?
Test_Ctx_Value_InGoroutine() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_Value_InGoroutine() defined?
Test_Ctx_Value_InGoroutine() is defined in ctx_test.go at line 3314.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free