@@ -1599,6 +1599,10 @@ func findProcess(
1599
1599
return matches , nil
1600
1600
}
1601
1601
1602
+ func pidExists (pid int ) bool {
1603
+ return syscall .ESRCH .Is (syscall .Kill (pid , 0 ))
1604
+ }
1605
+
1602
1606
func TestStopVM_Isolated (t * testing.T ) {
1603
1607
prepareIntegTest (t )
1604
1608
require := require .New (t )
@@ -1725,6 +1729,25 @@ func TestStopVM_Isolated(t *testing.T) {
1725
1729
require .NoError (err )
1726
1730
},
1727
1731
},
1732
+
1733
+ {
1734
+ name : "Suspend" ,
1735
+ withStopVM : true ,
1736
+
1737
+ createVMRequest : proto.CreateVMRequest {},
1738
+ stopFunc : func (ctx context.Context , fcClient fccontrol.FirecrackerService , req proto.CreateVMRequest ) {
1739
+ firecrackerProcesses , err := findProcess (ctx , findFirecracker )
1740
+ require .NoError (err , "failed waiting for expected firecracker process %q to come up" , firecrackerProcessName )
1741
+ require .Len (firecrackerProcesses , 1 , "expected only one firecracker process to exist" )
1742
+ firecrackerProcess := firecrackerProcesses [0 ]
1743
+
1744
+ err = firecrackerProcess .Suspend ()
1745
+ require .NoError (err , "failed to suspend Firecracker" )
1746
+
1747
+ _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : req .VMID })
1748
+ assert .NotNil (err )
1749
+ },
1750
+ },
1728
1751
}
1729
1752
1730
1753
fcClient , err := newFCControlClient (containerdSockPath )
@@ -1768,13 +1791,13 @@ func TestStopVM_Isolated(t *testing.T) {
1768
1791
// If the function above uses StopVMRequest, all underlying processes must be dead
1769
1792
// (either gracefully or forcibly) at the end of the request.
1770
1793
if test .withStopVM {
1771
- fcExists , err := process . PidExists ( fcProcess .Pid )
1772
- require .NoError (err , "failed to find firecracker" )
1773
- require .False (fcExists , "firecracker %s is still there" , vmID )
1794
+ fcExists := pidExists ( int ( fcProcess .Pid ) )
1795
+ assert .NoError (err , "failed to find firecracker" )
1796
+ assert .False (fcExists , "firecracker %s (pid=%d) is still there" , vmID , fcProcess . Pid )
1774
1797
1775
- shimExists , err := process . PidExists ( shimProcess .Pid )
1776
- require .NoError (err , "failed to find shim" )
1777
- require .False (shimExists , "shim %s is still there" , vmID )
1798
+ shimExists := pidExists ( int ( shimProcess .Pid ) )
1799
+ assert .NoError (err , "failed to find shim" )
1800
+ assert .False (shimExists , "shim %s (pid=%d) is still there" , vmID , shimProcess . Pid )
1778
1801
}
1779
1802
1780
1803
err = internal .WaitForPidToExit (ctx , time .Second , shimProcess .Pid )
0 commit comments