Skip to content

Commit 5cee30e

Browse files
authored
test: resolve flaky integration test timing issues (#3503)
1 parent 77679dd commit 5cee30e

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

tests/Agent/IntegrationTests/IntegrationTests/OpenTelemetry/OpenTelemetryMetricsTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ protected OpenTelemetryMetricsTestsBase(TFixture fixture, ITestOutputHelper outp
3535
{
3636
_fixture.AgentLog.WaitForLogLine(AgentLogFile.AgentConnectedLogLineRegex, TimeSpan.FromMinutes(1));
3737

38-
// otlp metrics export will be complete before the first analytics event harvest
39-
_fixture.AgentLog.WaitForLogLine(AgentLogFile.AnalyticsEventDataLogLineRegex, TimeSpan.FromMinutes(1));
38+
// Wait for actual OTLP metrics export (every 5s) rather than the analytics event
39+
// harvest (every 60s), which can race with the WaitForLogLine timeout on slow CI.
40+
_fixture.AgentLog.WaitForLogLine(AgentLogFile.OtlpMetricsExportedLogLineRegex, TimeSpan.FromMinutes(1));
4041

4142
_otlpSummaries = _fixture.GetCollectedOTLPMetrics();
4243
}

tests/Agent/IntegrationTests/IntegrationTests/OpenTelemetry/OpenTelemetryStressTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ protected OpenTelemetryStressTestsBase(TFixture fixture, ITestOutputHelper outpu
4040
_fixture.TestLogger.WriteLine($"Agent Log Path: {_fixture.AgentLog?.FilePath}");
4141
_fixture.AgentLog.WaitForLogLine(AgentLogFile.AgentConnectedLogLineRegex, TimeSpan.FromMinutes(2));
4242

43-
// Wait for workload to complete - give more time for all metrics to be collected
44-
_fixture.AgentLog.WaitForLogLine(AgentLogFile.AnalyticsEventDataLogLineRegex, TimeSpan.FromMinutes(5));
45-
46-
// Add extra delay to ensure all metrics are exported
47-
// Increased from 30 to 45 seconds for slower CI environments
48-
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(45));
43+
// Wait for at least 3 OTLP exports (every 5s) to ensure sufficient metric data.
44+
// This replaces a 60s analytic_event_data wait + 45s Thread.Sleep that added
45+
// ~105s of unnecessary delay.
46+
_fixture.AgentLog.WaitForLogLines(AgentLogFile.OtlpMetricsExportedLogLineRegex, TimeSpan.FromMinutes(2), 3);
4947

5048
// Don't specify exact count - just get what's available with a reasonable max
5149
_otlpSummaries = _fixture.GetCollectedOTLPMetrics(count: 1000);

tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/NetStandardLibraries/PerformanceMetrics.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ private static void StartAgent()
3535
// We need atleast one known GC invocation to verify our GC metrics.
3636
GC.Collect();
3737

38+
// GCSamplerV2 computes Gen0-only collections as: raw Gen0 count - raw Gen1 count
39+
// (see ImmutableGCSample). The full GC.Collect() above increments both Gen0 and
40+
// Gen1 raw counters by 1, so the Gen0-only count is 1 - 1 = 0. These two
41+
// Gen0-only collections each increment the raw Gen0 counter without affecting
42+
// Gen1, bringing it to (1+2) - 1 = 2 and ensuring the test sees a non-zero
43+
// Gen0 metric.
44+
GC.Collect(0);
45+
GC.Collect(0);
46+
3847
// Get everything started up and time for initial Sample().
3948
Thread.Sleep(TimeSpan.FromSeconds(10));
4049
}

0 commit comments

Comments
 (0)