controller/vm: add unit tests for VM Controller state machine#2634
Open
shreyanshjain7174 wants to merge 2 commits intomicrosoft:mainfrom
Open
controller/vm: add unit tests for VM Controller state machine#2634shreyanshjain7174 wants to merge 2 commits intomicrosoft:mainfrom
shreyanshjain7174 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
eeccba4 to
687d39e
Compare
687d39e to
ef82816
Compare
e8cacd2 to
4718b32
Compare
4718b32 to
09f8fa8
Compare
e179fe0 to
aba0d5f
Compare
2c926f4 to
5115d34
Compare
Adds narrow `vmLifetime` and `guestManager` seam interfaces in the vm package and threads them through Controller so the state machine can be exercised without booting a real Hyper-V VM. Production wiring is unchanged: CreateVM still hands the concrete `*vmmanager.UtilityVM` and `*guestmanager.Guest` into the Controller, and device-level sub-controllers (scsi, vpci, plan9, network) continue to receive the wider concrete types via dedicated fields. Test coverage focuses on production failure paths: TerminateVM cleanup-chain continuation when intermediate steps fail, transition to StateInvalid when uvm.Close errors, idempotency of TerminateVM/StartVM for the containerd retry case, exit-status and start-time accessor branches, ExecIntoHost guard and passthrough, DumpStacks capability gating, and the Update*/Stats/Wait/Create state guards for the most realistic wrong-state callers. Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
5115d34 to
b6fc890
Compare
mock_vm.go imports types from internal/vm/guestmanager and internal/cmd that are themselves gated to "windows && (lcow || wcow)". Without a build tag on the generated mock, the bare "windows" lint matrix in CI tries to typecheck mock_vm.go and fails because its imports have no buildable files. Add the same build constraint as the source interfaces (types.go) so the mock is excluded from bare-windows and bare-linux compilation, matching the existing pattern used by the vpci controller mocks. Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
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.
Depends on #2627 — must merge first.
Adds unit tests for the VM Controller state machine (
internal/controller/vm/). To make the Manager testable, two field types are changed to their existing interfaces (vmmanager.LifetimeManager, combinedGuestManager). Mocks are generated withmockgenfollowing theinternal/windows/mock/pattern.Tests are biased toward production failure paths — resource cleanup, state corruption, and half-started scenarios — rather than guard-check permutations.
30 test cases covering: TerminateVM transitions (idempotency, Created/Running→Terminated, Close fail→Invalid, Invalid recovery, Terminate() error swallowed with Close still called, CloseConnection() error swallowed with Close still called), CreateVM duplicate-call rejection, StartVM failure paths (uvm.Start fails→Invalid, listener/connection failure→Invalid, idempotency when already Running, wrong-state rejection), ExecIntoHost (terminal+stderr precondition, success, exec error), DumpStacks (supported, not supported, dump error), StartTime/ExitStatus for relevant states, representative guard checks (one per method for realistic wrong-state calls), and State.String() for all values. All tests run without admin or HCS.