Skip to content

Commit 3637cd9

Browse files
committed
Retry tests up to three times
1 parent 9aa53e7 commit 3637cd9

File tree

1 file changed

+57
-36
lines changed

1 file changed

+57
-36
lines changed

tests/Integrations/PCNTL/PCNTLTest.php

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
final class PCNTLTest extends IntegrationTestCase
99
{
1010
private static $acceptable_test_execution_time = 2;
11+
private const MAX_RETRIES = 3;
1112

1213
protected function ddSetUp()
1314
{
@@ -19,54 +20,74 @@ protected function ddSetUp()
1920
parent::ddSetUp();
2021
}
2122

23+
private function retryTest(callable $testCase, ...$args)
24+
{
25+
$attempts = 0;
26+
while ($attempts < self::MAX_RETRIES) {
27+
try {
28+
$testCase(...$args);
29+
return; // Test passed, exit the loop.
30+
} catch (\Throwable $e) {
31+
$attempts++;
32+
if ($attempts >= self::MAX_RETRIES) {
33+
throw $e; // Re-throw after max retries.
34+
}
35+
}
36+
}
37+
}
38+
2239
/**
2340
* @dataProvider dataProviderAllScripts
2441
*/
2542
public function testDoesNoHangAtShutdownWhenDisabled($scriptPath)
2643
{
27-
if ($scriptPath === (__DIR__ . '/scripts/long-running-manual-flush.php')) {
28-
$this->markTestSkipped('manual tracing cannot be done when the tracer is disabled because the "DDTrace\\*" classes are not available.');
29-
return;
30-
}
31-
32-
$start = \microtime(true);
33-
$this->executeCli(
34-
$scriptPath,
35-
[
36-
'DD_TRACE_CLI_ENABLED' => 'false',
37-
'DD_TRACE_SHUTDOWN_TIMEOUT' => 5000,
38-
]
39-
);
40-
$end = \microtime(true);
41-
$this->assertLessThan(self::$acceptable_test_execution_time, $end - $start);
44+
$this->retryTest(function ($scriptPath) {
45+
if ($scriptPath === (__DIR__ . '/scripts/long-running-manual-flush.php')) {
46+
$this->markTestSkipped('manual tracing cannot be done when the tracer is disabled because the "DDTrace\\*" classes are not available.');
47+
return;
48+
}
49+
50+
$start = \microtime(true);
51+
$this->executeCli(
52+
$scriptPath,
53+
[
54+
'DD_TRACE_CLI_ENABLED' => 'false',
55+
'DD_TRACE_SHUTDOWN_TIMEOUT' => 5000,
56+
]
57+
);
58+
$end = \microtime(true);
59+
$this->assertLessThan(self::$acceptable_test_execution_time, $end - $start);
60+
}, $scriptPath);
4261
}
4362

4463
/**
4564
* @dataProvider dataProviderAllScripts
4665
*/
4766
public function testDoesNoHangAtShutdownWhenEnabled($scriptPath)
4867
{
49-
if (extension_loaded('xdebug')) {
50-
$this->markTestSkipped('xdebug is enabled, which causes the tracer to slow down dramatically.');
51-
}
52-
53-
$start = \microtime(true);
54-
$this->executeCli(
55-
$scriptPath,
56-
[
57-
'DD_TRACE_CLI_ENABLED' => 'true',
58-
'DD_TRACE_SHUTDOWN_TIMEOUT' => 5000,
59-
],
60-
[],
61-
'',
62-
false,
63-
true
64-
);
65-
$end = \microtime(true);
66-
$this->assertLessThan(self::$acceptable_test_execution_time, $end - $start);
67-
if (\dd_trace_env_config("DD_TRACE_SIDECAR_TRACE_SENDER")) {
68-
\dd_trace_synchronous_flush();
69-
}
68+
$this->retryTest(function ($scriptPath) {
69+
if (extension_loaded('xdebug')) {
70+
$this->markTestSkipped('xdebug is enabled, which causes the tracer to slow down dramatically.');
71+
}
72+
73+
$start = \microtime(true);
74+
$this->executeCli(
75+
$scriptPath,
76+
[
77+
'DD_TRACE_CLI_ENABLED' => 'true',
78+
'DD_TRACE_SHUTDOWN_TIMEOUT' => 5000,
79+
],
80+
[],
81+
'',
82+
false,
83+
true
84+
);
85+
$end = \microtime(true);
86+
$this->assertLessThan(self::$acceptable_test_execution_time, $end - $start);
87+
if (\dd_trace_env_config("DD_TRACE_SIDECAR_TRACE_SENDER")) {
88+
\dd_trace_synchronous_flush();
89+
}
90+
}, $scriptPath);
7091
}
7192

7293
public function dataProviderAllScripts()

0 commit comments

Comments
 (0)