Skip to content

perf: enable PHPUnit 12 execution ordering and GC control in test configs#40697

Open
lbajsarowicz wants to merge 1 commit intomagento:2.4-developfrom
lbajsarowicz:perf/phpunit-execution-order-gc-optimization
Open

perf: enable PHPUnit 12 execution ordering and GC control in test configs#40697
lbajsarowicz wants to merge 1 commit intomagento:2.4-developfrom
lbajsarowicz:perf/phpunit-execution-order-gc-optimization

Conversation

@lbajsarowicz
Copy link
Copy Markdown
Contributor

@lbajsarowicz lbajsarowicz commented Apr 12, 2026

Summary

Enables three PHPUnit 12 configuration attributes across integration and unit test configs to improve test execution time and memory stability:

  • executionOrder="depends" (integration) — ensures @depends / #[Depends] chains execute in the correct order. Uses depends only (not depends,duration) to preserve the explicit "Memory Usage Tests run first" guarantee documented in the suite definition.
  • executionOrder="depends,duration" (unit) — respects dependency chains and schedules faster tests first. Safe here because there are no ordering constraints between unit test suites.
  • controlGarbageCollector="true" (both) — lets PHPUnit trigger gc_collect_cycles() periodically during long runs, preventing gradual memory bloat that causes slowdowns and OOM kills in CI. Thresholds: 50 tests for integration (heavier fixture graphs), 200 for unit (lightweight).

Problem

  1. Test ordering: The current configs use PHPUnit's default discovery order. 22 integration test files use @depends/#[Depends] (e.g. ConfigurableTest.php), but without executionOrder="depends", PHPUnit does not guarantee dependency chains execute correctly — leading to intermittent failures.

  2. Memory growth: Long integration test runs accumulate cyclic references from fixture graphs, DI containers, and service objects. Without periodic GC, PHP's refcount-based memory management cannot reclaim these, causing memory usage to grow monotonically until the process is killed or becomes swap-bound.

Changes

File Attribute Value Why
dev/tests/integration/phpunit.xml.dist executionOrder depends Respect @depends without reordering suites (preserves Memory Usage Tests priority)
dev/tests/integration/phpunit.xml.dist controlGarbageCollector true Periodic GC during long integration runs
dev/tests/integration/phpunit.xml.dist numberOfTestsBeforeGarbageCollection 50 Integration tests are heavy; GC every 50 tests
dev/tests/unit/phpunit.xml.dist executionOrder depends,duration Respect dependencies + run fast tests first
dev/tests/unit/phpunit.xml.dist controlGarbageCollector true Periodic GC during full suite runs
dev/tests/unit/phpunit.xml.dist numberOfTestsBeforeGarbageCollection 200 Unit tests are lighter; less frequent GC needed

Test plan

  • php vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist --list-suites — config accepted by PHPUnit 12.5.14
  • php vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist --no-coverage app/code/Magento/Catalog/Test/Unit/ — 2632 tests pass
  • All attributes validate against PHPUnit 12.5 XSD schema
  • CI integration tests pass with new config

References

⭐ Support my work

Do you like the fix? Remember to react with "👍🏻" to get it merged faster,
Then Sponsor me on Github so I can spend more time on fixing issues like this one.

Learn more at https://github.com/sponsors/lbajsarowicz

Resolved issues:

  1. resolves [Issue] perf: enable PHPUnit 12 execution ordering and GC control in test configs #40768: perf: enable PHPUnit 12 execution ordering and GC control in test configs

…figs

- Add `executionOrder="depends"` to integration test config to ensure
  @depends/@Depends chains are respected. Using `depends` only (not
  `depends,duration`) preserves the explicit "Memory Usage Tests run
  first" guarantee that the suite definition requires.

- Add `executionOrder="depends,duration"` to unit test config where
  there are no ordering constraints between suites, allowing PHPUnit
  to schedule faster tests first within each level.

- Add `controlGarbageCollector="true"` with thresholds of 50
  (integration) and 200 (unit) to periodically run PHP GC during
  long test suite runs, preventing gradual memory bloat that causes
  slowdowns and OOM kills in CI.
@m2-assistant
Copy link
Copy Markdown

m2-assistant Bot commented Apr 12, 2026

Hi @lbajsarowicz. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@lbajsarowicz
Copy link
Copy Markdown
Contributor Author

@magento run all tests

@engcom-Dash
Copy link
Copy Markdown
Contributor

@magento create issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P3 May be fixed according to the position in the backlog. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

[Issue] perf: enable PHPUnit 12 execution ordering and GC control in test configs

2 participants