@@ -2250,17 +2250,12 @@ func TestCreateVM_Isolated(t *testing.T) {
22502250 require .NoError (t , err , "unable to create client to containerd service at %s, is containerd running?" , integtest .ContainerdSockPath )
22512251 defer client .Close ()
22522252
2253- ctx := namespaces .WithNamespace (context .Background (), "default" )
2254-
2255- fcClient , err := integtest .NewFCControlClient (integtest .ContainerdSockPath )
2256- require .NoError (t , err , "failed to create ttrpc client" )
2257-
22582253 kernelArgs := integtest .DefaultRuntimeConfig .KernelArgs
22592254
22602255 type subtest struct {
22612256 name string
22622257 request proto.CreateVMRequest
2263- validate func (* testing.T , error )
2258+ validate func (* testing.T , context. Context , error )
22642259 validateUsesFindProcess bool
22652260 stopVM bool
22662261 }
@@ -2269,7 +2264,7 @@ func TestCreateVM_Isolated(t *testing.T) {
22692264 {
22702265 name : "Happy Case" ,
22712266 request : proto.CreateVMRequest {},
2272- validate : func (t * testing.T , err error ) {
2267+ validate : func (t * testing.T , ctx context. Context , err error ) {
22732268 require .NoError (t , err )
22742269 },
22752270 stopVM : true ,
@@ -2283,7 +2278,7 @@ func TestCreateVM_Isolated(t *testing.T) {
22832278 HostPath : "/var/lib/firecracker-containerd/runtime/rootfs-debug.img" ,
22842279 },
22852280 },
2286- validate : func (t * testing.T , err error ) {
2281+ validate : func (t * testing.T , ctx context. Context , err error ) {
22872282 require .NotNil (t , err , "expected an error but did not receive any" )
22882283 time .Sleep (5 * time .Second )
22892284 firecrackerProcesses , err := findProcess (ctx , findFirecracker )
@@ -2301,7 +2296,7 @@ func TestCreateVM_Isolated(t *testing.T) {
23012296 HostPath : "/var/lib/firecracker-containerd/runtime/rootfs-debug.img" ,
23022297 },
23032298 },
2304- validate : func (t * testing.T , err error ) {
2299+ validate : func (t * testing.T , ctx context. Context , err error ) {
23052300 require .Error (t , err )
23062301 assert .Equal (t , codes .DeadlineExceeded , status .Code (err ))
23072302 assert .Contains (t , err .Error (), "didn't start within 20s" )
@@ -2317,7 +2312,7 @@ func TestCreateVM_Isolated(t *testing.T) {
23172312 },
23182313 TimeoutSeconds : 60 ,
23192314 },
2320- validate : func (t * testing.T , err error ) {
2315+ validate : func (t * testing.T , ctx context. Context , err error ) {
23212316 require .NoError (t , err )
23222317 },
23232318 stopVM : true ,
@@ -2331,6 +2326,15 @@ func TestCreateVM_Isolated(t *testing.T) {
23312326 if ! s .validateUsesFindProcess {
23322327 t .Parallel ()
23332328 }
2329+
2330+ ctx , cancel := context .WithTimeout (context .Background (), 60 * time .Second )
2331+ defer cancel ()
2332+ ctx = namespaces .WithNamespace (ctx , "default" )
2333+
2334+ fcClient , err := integtest .NewFCControlClient (integtest .ContainerdSockPath )
2335+ require .NoError (t , err , "failed to create ttrpc client" )
2336+ defer fcClient .Close ()
2337+
23342338 vmID := testNameToVMID (t .Name ())
23352339
23362340 tempDir := t .TempDir ()
@@ -2349,7 +2353,7 @@ func TestCreateVM_Isolated(t *testing.T) {
23492353 requireNonEmptyFifo (t , metricsFile )
23502354
23512355 // Some test cases are expected to have an error, some are not.
2352- s .validate (t , createVMErr )
2356+ s .validate (t , ctx , createVMErr )
23532357
23542358 if createVMErr == nil && s .stopVM {
23552359 // Ensure the response fields are populated correctly
@@ -2360,6 +2364,8 @@ func TestCreateVM_Isolated(t *testing.T) {
23602364 TimeoutSeconds : 30 ,
23612365 })
23622366 require .Equal (t , status .Code (err ), codes .OK )
2367+
2368+ time .Sleep (500 * time .Millisecond )
23632369 }
23642370 }
23652371
0 commit comments