test: add cross-platform middleware dispatch contract test (closes #542)#547
Merged
Merged
Conversation
Locks in the invariant that the middleware pipeline dispatches each registered middleware exactly once per HTTP request, on every supported OS. Issue #533 exposed a macOS-only regression where middleware ran multiple times per request, so this contract test guards the entire dispatch-count class of bugs forever. Mechanics: - New DispatchCountMiddleware increments a flock-protected counter file per __invoke and tags the response with X-Dispatch-Count. - New dedicated test server on port 9991 in tests/App/Kernel.php with only the counting middleware (does not affect the existing 8888/9999 test servers or their contract assertions). - New /dispatch_count_test endpoint in ResponseTestController. - New MiddlewareDispatchContractTest with two cases: single request (counter == 1) and sequential requests (counter == 1 then 2). Tests skip cleanly when the daemon is not running on 9991. CHANGELOG entry added under [Unreleased] / Added. Tests: phpunit tests/MiddlewareDispatchContractTest.php passes locally (2 tests, 11 assertions). composer lint clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #542 — adds a contract test that locks in the invariant that the
middleware pipeline dispatches each registered middleware exactly once per
incoming HTTP request, on every supported OS.
Issue #533 exposed a macOS-only regression where middleware ran multiple
times per request. Without a contract test guarding the dispatch-count
class of bugs, future refactors of HttpRequestHandler / ServerWorker /
WorkerMiddlewareDispatchInterface could silently regress it on any OS,
including macOS in CI and Linux under wider conditions.
Changes
tests/App/DispatchCountMiddleware.php— a counting middlewarethat increments a shared counter file under
flock()per__invokeandtags every response with
X-Dispatch-Count: N.http://127.0.0.1:9991intests/App/Kernel.php—dedicated test server that runs only the counting middleware. Does not
touch the existing 8888/9999 servers or their contract assertions.
/dispatch_count_testinResponseTestController.php—trivial
text/plainbody used as the dispatch probe.tests/MiddlewareDispatchContractTest.php— two assertions of thecontract:
X-Dispatch-Countheader ===1and the shared counter file ===
1.1then2and the final counter file ===2.Both tests
markTestSkippedwhen the dedicated daemon on 9991 is notrunning, so they integrate with the existing
composer testworkflowvia the standard Workerman bootstrap (
tests/App/bootstrap.php).[Unreleased]/ Added linking to feat: Add cross-platform middleware dispatch contract test #542.Acceptance Criteria from #542
tests/MiddlewareDispatchContractTest.phptransport as the existing
MiddlewareTestso behavior is identicalacross platforms; no platform-specific assumptions)
composer testpasses locally — verified:1479 tests, 3020 assertionscomposer lintclean (php-cs-fixer, phpstan, rector)Changelog
Code Review
on file/lock open failures), PSR-12 via composer lint, no test
isolation issues (setUp/tearDown reset the counter file; skip when
daemon absent).