Skip to content

Commit 50c958a

Browse files
tippmar-nrclaude
andcommitted
fix: resolve flaky integration test timing issues
- GCSamplerV2 tests: add Gen0-only GC.Collect(0) calls so the V2 per-generation subtraction logic reliably reports non-zero Gen0 collections regardless of startup timing. - OTel metrics tests: wait for the OTLP export log line (fires every 5s) instead of analytic_event_data (fires at ~60s), which races with the 60-second WaitForLogLine timeout on slow CI machines. - OTel stress tests: replace the 60s analytics wait + 45s Thread.Sleep with a wait for 3 OTLP exports (~15s), cutting exercise time from ~123s to ~20s. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 425cdd1 commit 50c958a

3 files changed

Lines changed: 14 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ private static void StartAgent()
3535
// We need atleast one known GC invocation to verify our GC metrics.
3636
GC.Collect();
3737

38+
// Gen0-only collections ensure the GCSamplerV2's per-generation counting
39+
// (which subtracts higher-gen counts from lower-gen counts) reports non-zero
40+
// Gen0 collections. Without these, a full GC.Collect() increments all generation
41+
// counters equally, and the subtraction can yield zero on fast-starting processes.
42+
GC.Collect(0);
43+
GC.Collect(0);
44+
3845
// Get everything started up and time for initial Sample().
3946
Thread.Sleep(TimeSpan.FromSeconds(10));
4047
}

0 commit comments

Comments
 (0)