Skip to content

Add horizontal scaling tests for vmcp#4724

Open
yrobla wants to merge 1 commit intomainfrom
issue-4222
Open

Add horizontal scaling tests for vmcp#4724
yrobla wants to merge 1 commit intomainfrom
issue-4222

Conversation

@yrobla
Copy link
Copy Markdown
Contributor

@yrobla yrobla commented Apr 10, 2026

Summary

Add integration and e2e tests for Redis-backed vMCP session sharing

Integration tests (pkg/vmcp/server/sessionmanager, miniredis):

  • AC1: cross-pod session reconstruction via RestoreSession on cache miss
  • AC2: hijack prevention — wrong/nil callers rejected after restore, correct caller routes successfully
  • AC4: all backends unreachable on restore → empty routing table returned
  • AC5: NotifyBackendExpired removes backend from Redis metadata; subsequent restore on a fresh pod skips the expired backend
  • AC6: LocalSessionDataStorage (no Redis) → no cross-pod sharing

E2E tests (test/e2e/thv-operator/virtualmcp, Kind + real Redis):

  • replicas=2 + Redis → SessionStorageWarning=False and Ready=True
  • cross-pod session reconstruction: session initialized on pod A is usable on pod B via transport.WithSession(sessionID)

Note: AC3 (LRU eviction, RC-10) is intentionally excluded — TTL-based Redis eviction is sufficient.

Fixes #4222

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Changes

File Change

Does this introduce a user-facing change?

Special notes for reviewers

@yrobla yrobla requested a review from Copilot April 10, 2026 05:19
@github-actions github-actions bot added the size/L Large PR: 600-999 lines changed label Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds higher-level integration and end-to-end coverage for Redis-backed vMCP session sharing, focusing on cross-pod session restoration and related lifecycle behaviors.

Changes:

  • Added Go integration tests for sessionmanager using miniredis + in-process MCP backends to validate restore, hijack prevention, backend expiry metadata, and in-memory-only behavior.
  • Added operator E2E tests (Kind + real Redis) to validate VirtualMCPServer readiness/conditions with Redis and to exercise cross-pod session reuse via transport.WithSession(sessionID).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/vmcp/server/sessionmanager/horizontal_scaling_integration_test.go New integration tests covering cross-pod restore, hijack prevention, restore failure behavior, backend expiry metadata, and no-Redis isolation.
test/e2e/thv-operator/virtualmcp/virtualmcp_redis_session_test.go New E2E coverage for VirtualMCPServer replicas=2 with Redis: condition assertions and cross-pod session reconstruction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.76%. Comparing base (ed7e41b) to head (5c45f44).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4724      +/-   ##
==========================================
+ Coverage   68.60%   68.76%   +0.16%     
==========================================
  Files         516      517       +1     
  Lines       53841    54817     +976     
==========================================
+ Hits        36937    37695     +758     
- Misses      14057    14228     +171     
- Partials     2847     2894      +47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add integration and e2e tests for Redis-backed vMCP session sharing

Integration tests (pkg/vmcp/server/sessionmanager, miniredis):
- AC1: cross-pod session reconstruction via RestoreSession on cache miss
- AC2: hijack prevention — wrong/nil callers rejected after restore,
       correct caller routes successfully
- AC4: all backends unreachable on restore → empty routing table returned
- AC5: NotifyBackendExpired removes backend from Redis metadata;
       subsequent restore on a fresh pod skips the expired backend
- AC6: LocalSessionDataStorage (no Redis) → no cross-pod sharing

E2E tests (test/e2e/thv-operator/virtualmcp, Kind + real Redis):
- replicas=2 + Redis → SessionStorageWarning=False and Ready=True
- cross-pod session reconstruction: session initialized on pod A is
  usable on pod B via transport.WithSession(sessionID)

Note: AC3 (LRU eviction, RC-10) is intentionally excluded — TTL-based
Redis eviction is sufficient.

Closes #4222
@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Apr 10, 2026
@yrobla yrobla requested a review from Copilot April 10, 2026 05:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +25 to 27
func countReadyPods(vmcpName string) (int, error) {
podList, err := GetVirtualMCPServerPods(ctx, k8sClient, vmcpName, "default")
if err != nil {
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

countReadyPods now hardcodes the namespace as "default". This duplicates defaultNamespace used elsewhere in the test and makes the helper silently wrong if the suite is ever run in a non-default namespace. Consider reintroducing the namespace parameter (and pass defaultNamespace at call sites), or promote the namespace constant to package scope so the helper can reference it without a magic string.

Copilot uses AI. Check for mistakes.
Comment on lines 147 to +162
@@ -155,11 +155,11 @@ func portForwardToPod(podName, namespace string, targetPort int32) (int, func(),
_ = listener.Close()

kubeconfigArg := fmt.Sprintf("--kubeconfig=%s", kubeconfig)
//nolint:gosec // kubeconfig, namespace, podName, and ports are test-controlled values
//nolint:gosec // kubeconfig, podName, and ports are test-controlled values
cmd := exec.Command("kubectl", kubeconfigArg,
"-n", namespace, "port-forward",
"-n", "default", "port-forward",
fmt.Sprintf("pod/%s", podName),
fmt.Sprintf("%d:%d", localPort, targetPort))
fmt.Sprintf("%d:%d", localPort, 8080))
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

portForwardToPod now hardcodes both the namespace ("default") and the forwarded target port (8080). This introduces magic constants and can easily drift from the defaultNamespace/proxyPort values used elsewhere in this file (e.g., if the test is adjusted to run in another namespace or the proxy port changes). Consider accepting namespace and targetPort as parameters again, or centralizing these values as package-level constants reused by both the MCPServer and VirtualMCPServer tests.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@jerm-dro jerm-dro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for writing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integration tests for vMCP horizontal scaling (THV-0047)

4 participants