controller/vm: add unit tests for VM Controller state machine#2634
Draft
shreyanshjain7174 wants to merge 9 commits intomicrosoft:mainfrom
Draft
controller/vm: add unit tests for VM Controller state machine#2634shreyanshjain7174 wants to merge 9 commits intomicrosoft:mainfrom
shreyanshjain7174 wants to merge 9 commits intomicrosoft:mainfrom
Conversation
In this commit, we are adding the initial draft of `containerd-shim-lcow-v1`. This shim is used for running Linux Containers on Windows. As part of this commit, we are adding the following- - The main entrypoint and supporting logic to start + serve the shim server. - The stubs for Task Service and Shimdiag service. - The implementation for `Sandbox` service. - The implementation for `VM Controller` which manages the VM lifecycle and operations. Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Signed-off-by: Harsh Rawat <harshrawat@microsoft.com>
Change Manager.uvm from *vmmanager.UtilityVM to vmmanager.LifetimeManager and Manager.guest from *guestmanager.Guest to a new combined GuestManager interface. This enables dependency injection for unit testing with mocks. No behavioral change to production code. Signed-off-by: Shreyansh Sancheti <shreyanshjain7174@gmail.com> Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
Add go:generate mockgen directives and generate mocks for: - vmmanager.LifetimeManager - vm.Controller and vm.GuestManager - gcs.GuestDefinedCapabilities Signed-off-by: Shreyansh Sancheti <shreyanshjain7174@gmail.com> Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
Add 42 test cases covering: - State.String() for all states including unknown/negative values - TerminateVM state transitions (idempotency, success, error, recovery) - Guard checks for all state-dependent methods with error content validation - ExecIntoHost validation, success, non-zero exit code, and exec error paths - DumpStacks with supported/unsupported capabilities and dump error path - StartTime for all states - ExitStatus success and error cases (table-driven) - StartVM idempotency and error states (table-driven) Follows Go test best practices: - Table-driven tests with t.Run() and / separator for subtest names - t.Parallel() on all subtests for concurrent execution - defer ctrl.Finish() per repo convention (TestLookupVMMEM pattern) - t.Context() instead of context.Background() (Go 1.24+) - t.Errorf for independent assertions, t.Fatalf only for nil guards - Error content validation (not just err != nil) Signed-off-by: Shreyansh Sancheti <shreyanshjain7174@gmail.com> Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
- Use 'go tool mockgen' instead of bare 'mockgen' in go:generate directives (matches go.mod tool directive, ensures CI uses pinned version) - Add -build_constraint=windows to vmcontroller mock (imports Windows-only packages) - Remove stale internal/controller/vm/mock/ directory (tests use internal/test/mock/vmcontroller/) Signed-off-by: Shreyansh Sancheti <shreyanshjain7174@gmail.com> Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
CI uses oldstable (Go 1.23). t.Context() requires Go 1.24. Signed-off-by: Shreyansh Sancheti <shreyanshjain7174@gmail.com> 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. 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.42 test cases covering: