8
8
final class PCNTLTest extends IntegrationTestCase
9
9
{
10
10
private static $ acceptable_test_execution_time = 2 ;
11
+ private const MAX_RETRIES = 3 ;
11
12
12
13
protected function ddSetUp ()
13
14
{
@@ -19,54 +20,74 @@ protected function ddSetUp()
19
20
parent ::ddSetUp ();
20
21
}
21
22
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
+
22
39
/**
23
40
* @dataProvider dataProviderAllScripts
24
41
*/
25
42
public function testDoesNoHangAtShutdownWhenDisabled ($ scriptPath )
26
43
{
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 );
42
61
}
43
62
44
63
/**
45
64
* @dataProvider dataProviderAllScripts
46
65
*/
47
66
public function testDoesNoHangAtShutdownWhenEnabled ($ scriptPath )
48
67
{
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 );
70
91
}
71
92
72
93
public function dataProviderAllScripts ()
0 commit comments