Fix flaky E2E lifecycle tests: tool discovery race#4107
Merged
Conversation
Move tool-name assertions inside Eventually retry loops so tests retry with new MCP sessions until all backends are fully discovered. The root cause is that tool discovery is session-scoped: when a backend isn't ready when a session is created, it's silently skipped, producing incomplete tool lists. Tests then fail because they assert on specific tool names outside the retry loop (or have no retry at all). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4107 +/- ##
==========================================
- Coverage 68.68% 68.62% -0.07%
==========================================
Files 453 453
Lines 46011 46011
==========================================
- Hits 31604 31575 -29
- Misses 11967 11998 +31
+ Partials 2440 2438 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rdimitrov
approved these changes
Mar 11, 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.
Summary
Eventuallyretry loop (or have no retry at all).Eventuallyloops so each retry creates a fresh MCP session, triggering fresh backend discovery. Add reusable helper functions to reduce boilerplate across tests.Type of change
Test plan
task lint-fix)These are E2E operator tests that require a KIND cluster. The fix is structural (moving assertions inside retry loops) and does not change test semantics — only retry behavior. Full verification requires the "E2E Tests Lifecycle" CI workflow to pass across all K8s versions.
Changes
test/e2e/thv-operator/virtualmcp/wait_for_tools_helpers.goWaitForExpectedTools,WaitForExpectedToolsWithAuth,ToolsContainAll,ToolsContainSubstring,ToolsHavePrefixhelperstest/e2e/thv-operator/virtualmcp/virtualmcp_toolconfig_test.goItblocks: move tool-name assertions insideWaitForExpectedToolstest/e2e/thv-operator/virtualmcp/virtualmcp_conflict_resolution_test.goItblocks: wrap withWaitForExpectedTools(previously had NO retry)test/e2e/thv-operator/virtualmcp/virtualmcp_optimizer_circuit_breaker_test.goItblock: wrapcallFindToolfor echo + fetch insideEventuallytest/e2e/thv-operator/virtualmcp/virtualmcp_auth_discovery_test.goItblock: replaceInitializeMCPClientWithRetries+ immediate assert withWaitForExpectedToolsWithAuthDoes this introduce a user-facing change?
No
Special notes for reviewers
WaitForExpectedToolsWithAuthusesginkgo.DeferCleanupto ensure the last MCP client is closed even ifEventuallyexhausts retries and Ginkgo panics before the caller candefer Close().TestToolListingAndCall(inhelpers.go) has the same single-shot pattern but is partially mitigated byOrderedsuites where precedingItblocks warm up backends. Worth tracking as follow-up but not blocking for this PR.virtualmcp_aggregation_*.go,virtualmcp_optimizer_test.go, etc.) also use single-shot client creation. These haven't been observed to flake and can be addressed in a follow-up.Generated with Claude Code