Skip to content

test: fix flaky AgentCore metric assertions against process-global meter - #39

Merged
GarrettBeatty merged 1 commit into
feature/meaifrom
gcbeatty/fix-flaky-metric-tests
Aug 5, 2026
Merged

test: fix flaky AgentCore metric assertions against process-global meter#39
GarrettBeatty merged 1 commit into
feature/meaifrom
gcbeatty/fix-flaky-metric-tests

Conversation

@GarrettBeatty

Copy link
Copy Markdown
Contributor

Problem

The AWS CI check on PR #38 failed on a single flaky unit test:

AgentCoreInstrumentationTests.RecordInvocationDuration_EmitsErrorTypeTag_WhenFailed
Assert.Contains() Failure: Filter not matched in collection

(All 31 integration tests passed; dotnet test returned exit 1 solely because of this unit test.)

Root cause

AgentCoreMetrics uses a process-global static Meter/Histogram. The affected tests recorded a point and then asserted on GetFirstMetricPoint(metric) — the first point in the aggregation. AgentCoreEndpointExtensionsTests records invoke_agent duration points via the /invocations endpoint and is not in the [Collection("OTelIntegration")] group, so xUnit runs it in parallel. A competing point added during the test's MeterProvider window 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 GetFirstMetricPoint helper with GetMetricPointTags, 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

  • All 101 tests in AWS.AgentCore.Hosting.UnitTests pass locally (run in parallel).

Note

Test-only change with no shippable behavior — labeled Release Not Needed, so no .autover change file.

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.
@GarrettBeatty
GarrettBeatty requested review from a team as code owners August 5, 2026 18:45
@GarrettBeatty
GarrettBeatty requested review from normj and removed request for a team August 5, 2026 18:45
@GarrettBeatty GarrettBeatty added the Release Not Needed Add this label if a PR does not need to be released. label Aug 5, 2026
@GarrettBeatty
GarrettBeatty merged commit 736b2b8 into feature/meai Aug 5, 2026
5 of 9 checks passed
@GarrettBeatty
GarrettBeatty deleted the gcbeatty/fix-flaky-metric-tests branch August 5, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release Not Needed Add this label if a PR does not need to be released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants