-
-
Notifications
You must be signed in to change notification settings - Fork 0
test(http): Extract memory tests from ApplicationTest to ApplicationMemoryTest class.
#117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…onMemoryTest` class.
WalkthroughIntroduces a dedicated ApplicationMemoryTest with 13 memory-management test cases for StatelessApplication and removes the corresponding memory-related tests from ApplicationTest. No production code changes are included. Changes
Sequence Diagram(s)(omitted — changes are test reorganization only) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10–15 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #117 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 318 318
===========================================
Files 12 12
Lines 808 808
===========================================
Hits 808 808 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (5)
tests/http/stateless/ApplicationMemoryTest.php (5)
75-81: Compute the artificial limit without floats to guarantee boundary behavior.Using
/ 0.9can yield rounding surprises that flip the comparison on tight boundaries. Use integer math to computeceil(10*usage/9).- $artificialLimit = (int) ($currentUsage / 0.9); + // ceil(10 * usage / 9) without floats to ensure usage >= 0.9 * artificialLimit + $artificialLimit = intdiv($currentUsage * 10 + 8, 9);
100-132: Stabilize GC and superglobal mutations; assert on GC runs as well as collected cycles.
- Snapshot and restore GC enabled state and
$_SERVERvia try/finally.- On some PHP builds,
gc_status()['collected']can be 0 even when a run occurred with no remaining cycles to free. Asserting increase ingc_status()['runs']alongsidecollectedmakes this test more robust.Example adjustments (pattern):
$gcWasEnabled = function_exists('gc_enabled') ? gc_enabled() : true; $serverBackup = $_SERVER; try { if ($gcWasEnabled) { gc_disable(); // as intended by the test setup } // ... build circular refs and mutate $_SERVER $gcBefore = gc_status(); $runsBefore = $gcBefore['runs'] ?? 0; $collectedBefore = $gcBefore['collected'] ?? 0; $app->clean(); $gcAfter = gc_status(); $runsAfter = $gcAfter['runs'] ?? $runsBefore; $collectedAfter = $gcAfter['collected'] ?? $collectedBefore; self::assertGreaterThan($runsBefore, $runsAfter, 'GC should have run at least once.'); self::assertGreaterThan( $collectedBefore, $collectedAfter, 'GC should collect some cycles created in the loop.' ); } finally { $_SERVER = $serverBackup; if ($gcWasEnabled) { gc_enable(); } else { gc_disable(); } }Also applies to: 140-161
168-199: Optional: ensure output buffers are restored to baseline to avoid interference.
clearOutput()stops at a minimum level (1 in test env). For extra safety, capture the baseline level before opening local buffers and guarantee restoration in a finally block if the assertion fails.$baseline = ob_get_level(); try { ob_start(); ob_start(); ob_start(); // ... invoke clearOutput and assertions } finally { while (ob_get_level() > $baseline) { @ob_end_clean(); } }
69-70: Use a portable upper bound for memory_limit to avoid 32-bit overflows.
2Gcan exceedPHP_INT_MAXon 32-bit builds. You don’t rely on exactly 2G here, so 1G is safer and equivalent for the test’s intent.- ini_set('memory_limit', '2G'); + ini_set('memory_limit', '1G'); // portable across 32- and 64-bit builds
316-318: Clarify the comment about INT upper bound.On 64-bit PHP, 2_147_483_647 is not “near PHP_INT_MAX.” It’s near 32-bit INT_MAX. The code is fine; this is just a wording nit.
- $largeLimit = 2_147_483_647; // near 'PHP_INT_MAX' + $largeLimit = 2_147_483_647; // near 32-bit INT_MAX; well below 64-bit PHP_INT_MAX
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
tests/http/stateless/ApplicationMemoryTest.php(1 hunks)tests/http/stateless/ApplicationTest.php(0 hunks)
💤 Files with no reviewable changes (1)
- tests/http/stateless/ApplicationTest.php
🧰 Additional context used
🧬 Code graph analysis (1)
tests/http/stateless/ApplicationMemoryTest.php (4)
tests/support/FactoryHelper.php (2)
FactoryHelper(46-268)createServerRequestCreator(154-161)tests/TestCase.php (2)
TestCase(23-217)statelessApplication(124-187)src/http/StatelessApplication.php (4)
handle(269-295)getMemoryLimit(236-245)clean(141-152)setMemoryLimit(326-335)src/http/ErrorHandler.php (1)
clearOutput(81-96)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: phpunit / PHP 8.3-windows-latest
- GitHub Check: phpunit / PHP 8.4-windows-latest
- GitHub Check: phpunit / PHP 8.3-ubuntu-latest
- GitHub Check: phpunit / PHP 8.1-ubuntu-latest
- GitHub Check: mutation / PHP 8.3-ubuntu-latest
- GitHub Check: mutation / PHP 8.3-ubuntu-latest
🔇 Additional comments (1)
tests/http/stateless/ApplicationMemoryTest.php (1)
25-30: Good extraction and focused coverage on memory management.Solid split into a dedicated ApplicationMemoryTest with clear, intention-revealing names. Tests map well to StatelessApplication::clean(), ::getMemoryLimit(), and ::setMemoryLimit() semantics.
Summary by CodeRabbit