controller/vm: add comprehensive unit tests for VM Controller#2738
Open
shreyanshjain7174 wants to merge 2 commits into
Open
controller/vm: add comprehensive unit tests for VM Controller#2738shreyanshjain7174 wants to merge 2 commits into
shreyanshjain7174 wants to merge 2 commits into
Conversation
…faces Deferred SCSI controller setup from VM creation to first use, making SCSIController context-aware and fallible. Introduced internal utilityVM and guestManager interfaces on vm.Controller to decouple from concrete vmmanager/guestmanager types and enable mocking. Propagated the new signature through the LCOW pod controller and updated/regenerated the affected mocks and tests. Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
This was referenced May 14, 2026
Extends rawahars's interface refactor (utilityVM, guestManager, listenHVSock, createVM) with five additional package-level function variables for test injection: newGuestManager, lookupVMMEM, getProcessMemoryInfo (shared), buildSandboxConfig and parseUVMReferenceInfo (LCOW-only). Also fixes the WCOW setupLoggingListener to use the injected listenHVSock var instead of calling winio.ListenHvsock directly. Adds 62 unit tests (LCOW) / 61 (WCOW) covering: state machine guards, TerminateVM cleanup chain (Close failure to Invalid, CloseConnection error logged not returned, double-terminate idempotency), StartVM error cascade (PrepareConnection, Start, CreateConnection failures each transition to Invalid), waitForVMExit background goroutine race with TerminateVM, ExecIntoHost precondition checks and active-count tracking, DumpStacks capability branching, Wait dual-wait semantics, Stats vmmem lookup and memory reporting (VA-backed vs physically-backed), and concurrent access under the race detector. All tests run without admin or HCS. Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
0481c1a to
8b78ebf
Compare
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.
Supersedes #2634.
Tracks: #2668
Summary
Adds comprehensive unit tests for the VM Controller state machine (
internal/controller/vm/). Tests cover all public methods onControllerand are biased toward production failure paths — resource cleanup chains, state corruption, and half-started scenarios — rather than guard-check permutations.Changes
Source changes
types.go: SlimutilityVMandguestManagerinterfaces with platform-specific embedding (platformUVM,platformGuestManager); package-levellistenHVSock,createVM,newGuestManagervars for test injectionvm_lcow.go: Package-levelbuildSandboxConfig,parseUVMReferenceInfovars for test injectionvm_wcow.go: WCOWlistenHVSockimplementation (returns no-op listener)Test files
vm_test.go(build tag:lcow || wcow) — 73 cross-platform testsvm_createvm_lcow_test.go(build tag:lcow) — 4 LCOW-only tests (requireslcow.SandboxOptionsimport)platform_lcow_test.go/platform_wcow_test.go—isLCOW()helper via build tagsmocks/mock_types.go— gomock mocks forutilityVMandguestManagerTest coverage (83 LCOW / 73 WCOW)
All tests run without admin privileges or HCS.