Skip to content

Commit b29a3e6

Browse files
authored
test(CI): fix test_extension_ci failures across all PHP versions (#3663)
* test(CI): fix bug in request replayer Signed-off-by: Alexandre Rulleau <alexandre.rulleau@datadoghq.com> * fix(tests): filter remote config requests from CLI trace retrieval The sidecar now reliably connects during CLI subprocess lifetime (after the race condition fix), causing remote config polls to land in the request-replayer dump before the actual trace request. getAgentRequestFromCommand() was taking the first non-telemetry request from the dump, which could be a /v0.7/config remote config request instead of a trace. This caused flattenTraces() to receive the remote config payload and fail with a TypeError when iterating over span data. Fix: filter for the first actual trace request (uri starting with /v0.4/traces or /v0.7/traces) instead of taking [0]. * test(CI): fix pnctl tests Signed-off-by: Alexandre Rulleau <alexandre.rulleau@datadoghq.com> * test(CI): fix crashtracking disabled test Signed-off-by: Alexandre Rulleau <alexandre.rulleau@datadoghq.com> * test(CI): use try/catch in crashtracker_disabled test to avoid STDERR dependency Different PHP versions ship different run-tests.php implementations with different STDERR handling. Some versions don't include STDERR in the comparison buffer, causing the Fatal error message to be missed. Use try/catch to explicitly echo the timeout message to STDOUT so the EXPECT section matches reliably across all PHP versions. Also revert request-replayer image tag back to 2.0 (not 2.0-debug). * test(CI): use EXPECTF with %A to handle Segmentation fault output system() outputs "Segmentation fault (core dumped)" to stdout from the shell when the child process dies with SIGSEGV. Use EXPECTF with %A wildcards so the pattern matches regardless of this extra output, while still reliably matching "wait for replay timeout" from the try/catch. * test(CI): fix EXPECTF pattern for crashtracker_segfault_disabled The EXPECTF pattern '%Await for replay timeout\n%A' generates the regex '^.*wait for replay timeout\n.*$'. However run-tests.php trims the test output, so there is no trailing newline and the \n after 'timeout' never matches. Remove the trailing '%A' line so the regex becomes '^.*wait for replay timeout$' which matches the trimmed output: 'Segmentation fault (core dumped)\nwait for replay timeout' * test(CI): use previous request-replayer version Signed-off-by: Alexandre Rulleau <alexandre.rulleau@datadoghq.com> --------- Signed-off-by: Alexandre Rulleau <alexandre.rulleau@datadoghq.com>
1 parent f785afe commit b29a3e6

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

.gitlab/generate-common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function dockerhub_login() {
104104
SNAPSHOT_REGEX_PLACEHOLDERS: 'path:/\S+/dd-trace-php(?=/),httpbin:(?<=//)httpbin-integration:8080'
105105

106106
request-replayer:
107-
name: registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:php-request-replayer-2.0
107+
name: registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:php-request-replayer-2.0@sha256:4f26c11d568d2401bdd35d592aeff003b89b289e525166ee5ad376066877e4ad
108108
alias: request-replayer
109109
command: ["php", "-S", "<?= $service_bind_address ?>:80", "index.php"]
110110
variables:

tests/Common/CLITestCase.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ public function getTracesFromCommand($arguments = '', $overrideEnvs = [])
7575
public function getAgentRequestFromCommand($arguments = '', $overrideEnvs = [])
7676
{
7777
$this->executeCommand($arguments, $overrideEnvs);
78-
return $this->retrieveDumpedTraceData()[0] ?? [];
78+
foreach ($this->retrieveDumpedTraceData() as $request) {
79+
$uri = $request['uri'] ?? '';
80+
if (strpos($uri, '/v0.4/traces') === 0 || strpos($uri, '/v0.7/traces') === 0) {
81+
return $request;
82+
}
83+
}
84+
return [];
7985
}
8086

8187
/**

tests/Common/TracerTestTrait.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,9 @@ public function retrieveAnyDumpedData($until, $throw, $metrics = false) {
535535
public function retrieveDumpedTraceData($until = null, $throw = false)
536536
{
537537
return array_values(array_filter($this->retrieveDumpedData($until, $throw), function ($request) {
538-
// Filter telemetry requests
539-
return strpos($request["uri"] ?? "", "/telemetry/") !== 0;
538+
// Only return actual trace requests, filtering out telemetry, remote config, etc.
539+
$uri = $request["uri"] ?? "";
540+
return strpos($uri, "/v0.4/traces") === 0 || strpos($uri, "/v0.7/traces") === 0;
540541
}));
541542
}
542543

@@ -566,7 +567,9 @@ function untilTelemetryRequest($metricName) {
566567

567568
function untilSpan(SpanAssertion $assertion) {
568569
return function ($request) use ($assertion) {
569-
if (strpos($request["uri"] ?? "", "/telemetry/") === 0 || !isset($request['body'])) {
570+
$uri = $request["uri"] ?? "";
571+
$isTrace = strpos($uri, "/v0.4/traces") === 0 || strpos($uri, "/v0.7/traces") === 0;
572+
if (!$isTrace || !isset($request['body'])) {
570573
return false;
571574
}
572575
$traces = $this->parseRawDumpedTraces(json_decode($request['body'], true));

0 commit comments

Comments
 (0)