Skip to content

Conversation

@terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Aug 21, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

Summary by CodeRabbit

  • Tests
    • Added a focused test suite validating memory-limit handling, cleanup thresholds (90%), garbage-collection effects, and output-buffer clearing across simulated requests.
    • Removed overlapping memory-related tests from the legacy suite to eliminate duplication.
    • Expanded coverage for unlimited memory, dynamic memory-limit recalculation after config changes, and consistent behavior across multiple requests.

@terabytesoftw terabytesoftw added the bug Something isn't working label Aug 21, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 21, 2025

Walkthrough

Introduces 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

Cohort / File(s) Summary of changes
Add memory-focused test suite
tests/http/stateless/ApplicationMemoryTest.php
New test class with 13 methods covering memory thresholds, cleanup decisions, GC triggering, output buffer clearing, unlimited memory handling, and memory-limit recalculation/overrides.
Prune memory tests from general suite
tests/http/stateless/ApplicationTest.php
Removed 13 memory-related tests and associated imports/helpers from the broader ApplicationTest.

Sequence Diagram(s)

(omitted — changes are test reorganization only)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

Possibly related PRs

Poem

I hop through heaps and count each byte,
I nudge the GC to make things light.
Tests moved to nests where memory sings,
Buffers cleared and threshold rings.
Rabbit cheers — tidy tests take flight! 🐇✨

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 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.

📥 Commits

Reviewing files that changed from the base of the PR and between f9a3121 and 666ab97.

📒 Files selected for processing (1)
  • tests/http/stateless/ApplicationMemoryTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/http/stateless/ApplicationMemoryTest.php
⏰ 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)
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-mini-100

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fa697d8) to head (666ab97).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a 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.9 can yield rounding surprises that flip the comparison on tight boundaries. Use integer math to compute ceil(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 $_SERVER via 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 in gc_status()['runs'] alongside collected makes 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.

2G can exceed PHP_INT_MAX on 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.

📥 Commits

Reviewing files that changed from the base of the PR and between fa697d8 and f9a3121.

📒 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.

@terabytesoftw terabytesoftw merged commit 42d4125 into main Aug 21, 2025
29 checks passed
@terabytesoftw terabytesoftw deleted the fix-mini-100 branch August 21, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants