From cb49547276b2bfed151e2d3580e75f3de1fd8c59 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Thu, 15 Oct 2026 22:37:24 +0200 Subject: [PATCH] [TwigComponent] Fix the flaky render time assertion of the data collector test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit | Q | A | -------------- | --- | Bug fix? | no | New feature? | no | Deprecations? | no | Documentation? | no | Issues | | License | MIT `TwigComponentDataCollectorTest::testLateCollectWithCollectedData()` expects a positive render time between a `PreRenderEvent` and a `PostRenderEvent` logged back to back. Both events get their time from `microtime(true)`, which often returns the same value for two calls that close. Repeating the sequence of the test 10,000 times gives a render time of `0.0` in 7,472 runs. The test now waits 1 µs between the two events, and the same 10,000 runs never give `0.0`. The failure showed up at random in the TwigComponent suite while working on #4107, in 4 of 6 full runs. --- .../tests/Unit/DataCollector/TwigComponentDataCollectorTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/TwigComponent/tests/Unit/DataCollector/TwigComponentDataCollectorTest.php b/src/TwigComponent/tests/Unit/DataCollector/TwigComponentDataCollectorTest.php index d9f818fa9f3..82fde7c8b22 100644 --- a/src/TwigComponent/tests/Unit/DataCollector/TwigComponentDataCollectorTest.php +++ b/src/TwigComponent/tests/Unit/DataCollector/TwigComponentDataCollectorTest.php @@ -74,6 +74,8 @@ public function testLateCollectWithCollectedData(bool $collectComponents): void $mounted = new MountedComponent('foo', new \stdClass(), new ComponentAttributes([], new EscaperRuntime())); $eventA = new PreRenderEvent($mounted, new ComponentMetadata(['key' => 'foo', 'template' => 'bar']), []); $logger->onPreRender($eventA); + // without it, both events often get the same microtime() and the render time is 0.0 + usleep(1); $eventB = new PostRenderEvent($mounted); $logger->onPostRender($eventB);