🐛 bug: Fix Test method returning empty response on timeout#4063
🐛 bug: Fix Test method returning empty response on timeout#4063ReneWerner87 merged 6 commits intomainfrom
Conversation
Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
Co-authored-by: ReneWerner87 <7063188+ReneWerner87@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes App.Test() returning ErrTestGotEmptyResponse when a timeout occurs by changing timeout handling so the connection isn’t closed when FailOnTimeout is false, allowing the handler to finish writing a response.
Changes:
- Updated
App.Test()timeout behavior to only close the test connection whenFailOnTimeoutistrue. - Adjusted multiple “interrupted” tests to explicitly set
FailOnTimeout: trueand assert a timeout error. - Added/updated regression tests to validate behavior for small timeouts and
FailOnTimeoutmodes.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| app.go | Changes timeout branch in App.Test() to avoid closing the connection when FailOnTimeout=false. |
| app_test.go | Updates existing timeout test expectations and adds new regression tests for small-timeout behavior. |
| ctx_test.go | Updates interrupted stream-writer test to assert timeout error when FailOnTimeout=true. |
| adapter_test.go | Updates interrupted adaptor test to expect timeout error + nil response when FailOnTimeout=true. |
| middleware/adaptor/adaptor_test.go | Same interrupted-test update for middleware adaptor package. |
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: gaby <835733+gaby@users.noreply.github.com>
All review feedback has been addressed in commit a2594f7. Key changes:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4063 +/- ##
==========================================
- Coverage 91.11% 91.02% -0.09%
==========================================
Files 119 119
Lines 11207 11211 +4
==========================================
- Hits 10211 10205 -6
- Misses 630 638 +8
- Partials 366 368 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
The
app.Test()method returns "test: got empty response" errors when timeouts occur, breaking tests that worked in v2. Root cause: connection closes on timeout beforeServeConnfinishes writing the response, leaving the read buffer empty.Changes introduced
Core Fix (app.go)
Modified timeout handling in
Test():FailOnTimeout: true→ closes connection, returns timeout error (unchanged)FailOnTimeout: false→ waits up to 1 additional second for handler to complete, preventing indefinite blocking while allowing handlers to finishTest Updates
Updated tests expecting interrupted behavior to explicitly set
FailOnTimeout: trueAdded regression tests verifying both timeout modes work correctly with explicit delays to ensure reliable timeout triggering
Fixed test that incorrectly expected empty response with
FailOnTimeout: falseReduced sleep/timeout values in tests from 1s/100ms to 50ms/10ms for faster test suite execution
Updated timeout test assertion to use
ErrorIsfor specific error validationBenchmarks: No performance impact - same code paths, adds maximum 1 second wait when FailOnTimeout is false
Documentation Update: N/A - behavior now matches documented intent while preventing indefinite blocking
Changelog/What's New: Fixes Test method empty response error on timeout with bounded wait time
Migration Guide: No migration needed - fixes buggy behavior, breaking change only for tests relying on the bug
API Alignment with Express: N/A
API Longevity: Clarifies existing API semantics without changing signature, maintains timeout as safety limit
Examples: Test cases demonstrate both timeout modes with proper assertions
Type of change
Checklist
/docs/directory for Fiber's documentation.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.