From 4c558bdf4a3330f5605f759055d58b1b36e9ca35 Mon Sep 17 00:00:00 2001 From: Alexandre Rulleau Date: Thu, 23 Apr 2026 14:42:19 +0200 Subject: [PATCH] tests(appsec): wait for sidecar telemetry ready before running TelemetryTests Add a startup health-check in @BeforeAll that uses waitForMetrics() to wait for waf.init telemetry (up to 60s) before releasing any test. This eliminates the race between a slow helper/sidecar startup and the first test's polling window, which was causing all 9 ordered tests to time out in sequence. Also increase the @Order(1) test's waitForMetrics timeout from 30s to 60s, since @BeforeAll may consume the first waf.init batch (10s metric interval) and the test needs headroom to catch the next emission cycle. --- .../appsec/php/integration/TelemetryTests.groovy | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/appsec/tests/integration/src/test/groovy/com/datadog/appsec/php/integration/TelemetryTests.groovy b/appsec/tests/integration/src/test/groovy/com/datadog/appsec/php/integration/TelemetryTests.groovy index e71ba8f40d5..c92d80c1373 100644 --- a/appsec/tests/integration/src/test/groovy/com/datadog/appsec/php/integration/TelemetryTests.groovy +++ b/appsec/tests/integration/src/test/groovy/com/datadog/appsec/php/integration/TelemetryTests.groovy @@ -62,6 +62,17 @@ class TelemetryTests { export DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS=1; php-fpm -y /etc/php-fpm.conf -c /etc/php/php-rc.ini''') assert res.exitCode == 0 + + // Wait for the helper/sidecar to fully connect and flush its initial waf.init + // telemetry before releasing any test. Without this, a slow sidecar startup + // exhausts the first test's 60s polling window before any metric arrives, + // causing all 9 ordered tests to fail in sequence. + log.info('Waiting for sidecar to emit waf.init telemetry (up to 60s)...') + TelemetryHelpers.waitForMetrics(CONTAINER, 60) { List messages -> + def allSeries = messages.collectMany { it.series } + allSeries.any { it.name == 'waf.init' } + } + log.info('Sidecar telemetry ready — waf.init received.') } /** @@ -118,7 +129,9 @@ class TelemetryTests { TelemetryHelpers.Metric workerCount - TelemetryHelpers.waitForMetrics(CONTAINER, 30) { List messages -> + // 60s: @BeforeAll may have consumed the first waf.init batch (10s metric interval), + // so this test needs enough headroom to catch the next emission cycle. + TelemetryHelpers.waitForMetrics(CONTAINER, 60) { List messages -> def allSeries = messages.collectMany { it.series } wafInit = allSeries.find { it.name == 'waf.init' } // Rust helper has +1 tag (helper_runtime), C++ doesn't