test: fix flaky AgentCore metric assertions against process-global meter - #39
Merged
Merged
Conversation
RecordInvocationDuration/Memory* assertions took the first metric point from a process-global static Meter and asserted on its tags. Test classes that record invoke_agent points in parallel (e.g. AgentCoreEndpointExtensionsTests, not in the OTelIntegration collection) could add a competing point, so the first point was not necessarily this test's. Match against all metric points instead of assuming a single one.
normj
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
AWS CIcheck on PR #38 failed on a single flaky unit test:(All 31 integration tests passed;
dotnet testreturned exit 1 solely because of this unit test.)Root cause
AgentCoreMetricsuses a process-global staticMeter/Histogram. The affected tests recorded a point and then asserted onGetFirstMetricPoint(metric)— the first point in the aggregation.AgentCoreEndpointExtensionsTestsrecordsinvoke_agentduration points via the/invocationsendpoint and is not in the[Collection("OTelIntegration")]group, so xUnit runs it in parallel. A competing point added during the test'sMeterProviderwindow could make the first point the wrong one, so the assertion failed. Busy CI hosts hit the race; quiet dev machines don't (passes 13/13 locally in isolation).Fix
Replaced the
GetFirstMetricPointhelper withGetMetricPointTags, which collects the tag-set of every metric point, and changed all four assertions to look for a matching point across the full set instead of assuming a single one. This fixes the assertion's real weakness rather than masking the parallelism.Testing
AWS.AgentCore.Hosting.UnitTestspass locally (run in parallel).Note
Test-only change with no shippable behavior — labeled
Release Not Needed, so no.autoverchange file.