Skip to content

Integration tests for vMCP horizontal scaling (THV-0047) #4222

Closed

Description

@yrobla

Description

Add integration tests covering the end-to-end vMCP horizontal scaling scenario implemented by TASK-001 through TASK-007 in the vMCP epic (stacklok/stacklok-epics#262). These tests verify that session reconstruction, cross-pod hijack prevention, LRU eviction, and Redis metadata lifecycle work correctly together, using miniredis to avoid a live Redis dependency.

Parent epic: stacklok/stacklok-epics#262

Dependencies: #283 (RC-9: Reconstruct vMCP Sessions from Redis on Cache Miss), #285 (RC-10: LRU Eviction), #276 (RC-16: Update Redis Metadata When Backend Sessions Expire)

Context

Individual task issues (TASK-001 through TASK-007) include unit-test acceptance criteria for their respective packages. This task adds higher-level integration tests that exercise the full session lifecycle across the components introduced by those tasks, analogous to TASK-008 in the operator epic (stacklok/stacklok-epics#284).

Acceptance Criteria

  • Integration test: session created on "pod A" (Redis-backed manager) can be reconstructed and served on "pod B" (second Redis-backed manager pointing at the same miniredis instance) via GetMultiSession cache-miss path
  • Integration test: hijack prevention is enforced cross-pod — a request with a different token cannot use a session restored from Redis
  • Integration test: LRU eviction on "pod A" causes session to be evicted from memory; subsequent GetMultiSession call triggers RestoreSession from Redis and succeeds
  • Integration test: when all backends fail to reconnect during RestoreSession, session is returned with empty routing table (not an error), consistent with makeSession partial-failure behavior
  • Integration test: when a backend session expires (RC-16), the corresponding Redis metadata keys are removed; a subsequent RestoreSession does not attempt to reconnect that backend
  • Integration test: when Redis is not configured (nil RedisConfig), vMCP operates with in-memory-only storage and the above multi-pod scenarios are not exercised (verifies R-VMCP-4 regression guard)
  • All tests use miniredis.RunT(t) — no live Redis required
  • All tests pass: go test ./pkg/vmcp/... ./pkg/transport/session/...

Technical Approach

Test Location

Add a new file pkg/vmcp/server/sessionmanager/horizontal_scaling_integration_test.go (or equivalent) containing table-driven tests that:

  1. Spin up a miniredis instance
  2. Create two transportsession.Manager instances both backed by the same RedisStorage
  3. Use the first manager to create a session (simulating pod A)
  4. Use the second manager's GetMultiSession to reconstruct the session on a cache miss (simulating pod B)
  5. Verify the reconstructed session responds correctly to tool calls with the original caller identity

Patterns & Frameworks

  • github.com/alicebob/miniredis/v2 — in-process Redis for tests; follow pattern in pkg/authserver/storage/redis_test.go
  • Table-driven, t.Parallel() style — follow pkg/transport/session/storage_test.go
  • Fake backend connector pattern — follow pkg/vmcp/session/connector_integration_test.go

Code Pointers

  • pkg/vmcp/server/sessionmanager/session_manager.go — GetMultiSession with Redis fallback (added in TASK-005)
  • pkg/vmcp/session/factory.go — RestoreSession (added in TASK-005)
  • pkg/vmcp/session/internal/security/security.go — RestoreHijackPrevention (added in TASK-004)
  • pkg/transport/session/storage_redis.go — RedisStorage (added in TASK-001)
  • pkg/transport/session/manager.go — NewManagerWithRedis (added in TASK-002)
  • pkg/authserver/storage/redis_test.go — miniredis helper pattern to follow

Out of Scope

  • E2E tests against a real Kubernetes cluster
  • Load or performance testing
  • Operator-level integration tests (covered in stacklok/stacklok-epics#284)

References

Activity

  1. added
    vmcp
    scalability
    on Mar 18, 2026
  2. added
    enhancement
    go
    on Mar 18, 2026
  3. self-assigned this
    on Apr 9, 2026
  4. added 6 commits that reference this issue on Apr 10, 2026
    5c45f44
    5cb456e
    391139d
    cd63100
    2accd73
    94c85a4
  5. yrobla commented on Apr 14, 2026

    @yrobla
    ContributorAuthor

    This is the implementation issue for TASK-008 in epic stacklok/stacklok-epics#262 (Horizontal Scaling for vMCP). The epic is now correctly tracking this issue as a sub-issue.

    The integration test file (pkg/vmcp/server/sessionmanager/horizontal_scaling_integration_test.go) has not been created yet — this issue remains open. stacklok-epics#288 (the planning-level tracking issue) has been reopened to match.

  6. yrobla commented on Apr 14, 2026

    @yrobla
    ContributorAuthor

    Implemented by #4724, which covers all acceptance criteria:

    • AC1: cross-pod session reconstruction (TestHorizontalScaling_CrossPodReconstruction)
    • AC2: hijack prevention cross-pod (TestHorizontalScaling_CrossPodHijackPrevention)
    • AC3: intentionally omitted — LRU eviction (RC-10) was dropped; TTL-based Redis eviction is sufficient
    • AC4: all backends fail on restore → empty routing table (TestHorizontalScaling_AllBackendsFailOnRestore)
    • AC5: NotifyBackendExpired removes Redis metadata, restore skips expired backend (TestHorizontalScaling_BackendExpiry_SkipsExpiredOnRestore)
    • AC6: in-memory-only mode, no cross-pod sharing (TestHorizontalScaling_InMemoryOnlyMode)

    E2E tests in test/e2e/thv-operator/virtualmcp/virtualmcp_redis_session_test.go additionally cover pod restart recovery and cross-pod lazy eviction.

  7. added a commit that references this issue on Apr 15, 2026
    9176e93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgoscalabilityvmcp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions