hcs: add function variables for compute API calls and unit tests#2644
hcs: add function variables for compute API calls and unit tests#2644shreyanshjain7174 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
3a910f6 to
11ebebd
Compare
c35f103 to
c65d060
Compare
rawahars
left a comment
There was a problem hiding this comment.
Please add some comments on what we are trying to test in each case.
Some comments within the test case itself and method doc too.
helsaawy
left a comment
There was a problem hiding this comment.
I am not sure the benefit we get from this: the double indirection of function variables in both zsyscall_compute.go and export_test.go (as well as having system_test.go be in a dedicated testing module) feels very overcomplicated.
it honestly might be simpler/easier to start and manage actual HCS compute systems, since we would need to test that functionality isolated from the uvm package anyways
|
Thanks for the feedback, both. @helsaawy — fair point on the double indirection. The On whether real HCS functional tests would be simpler — for the trivial guard tests (closed handle, swallowed errors), yes. But the async notification tests (system exit during pending Start, service disconnect during Start, waitBackground exit classification, late callback after unregister) exercise race-sensitive paths that are hard to reproduce reliably against a live system. Those are the ones I want to keep — the rest I can trim. @rawahars — will add test comments explaining what each case exercises. Plan: move tests to Can I get an Ack @helsaawy ? |
c65d060 to
c80927a
Compare
|
Pushed the update addressing both reviews: @helsaawy — moved tests into Trimmed the trivial guard tests (closed-handle checks, shutdown/terminate swallowing) — those are 3-line @rawahars — added doc comments on every test explaining what scenario it exercises and why it matters (VM crash during boot, HCS service disconnect, unexpected exit classification, fan-out, late callback safety). |
Replace direct vmcompute.HcsXxx() calls in system.go and process.go with package-level function variables (hcsXxx) defined in zsyscall_compute.go. The variables default to the vmcompute functions. Tests swap individual variables to intercept specific operations. Tests are in package hcs (internal) so they access the function vars directly — no wrapper layer needed. 9 tests covering: synchronous and async Start completion, system exit during pending Start (VM crash at boot), HCS service disconnect during pending Start, system exit during pending Pause, waitBackground exit classification (normal vs unexpected), multi-goroutine Wait fan-out, and late callback arrival after unregistration. Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
c80927a to
780907d
Compare
The HCS layer (
internal/hcs/system.go,process.go) callsvmcompute.dlldirectly today — testing the System/Process lifecycle logic requires admin privileges and a running HCS service.This replaces the direct
vmcompute.HcsXxx()calls with package-level function variables (hcsXxx) defined inzsyscall_compute.go. The variables default to the vmcompute functions. Tests swap individual variables to intercept specific operations — no interface, no mock framework, no passthrough struct.Tests are in
package hcs(internal) so they access the function vars directly — no wrapper layer.No behavioral change. The function variables delegate to the exact same vmcompute functions.
9 tests covering: synchronous and async Start completion, system exit during pending Start (VM crash at boot), HCS service disconnect during pending Start, system exit during pending Pause, waitBackground exit classification (normal vs unexpected), multi-goroutine Wait fan-out, and late callback arrival after unregistration.