@@ -17,7 +17,6 @@ import (
1717 "context"
1818 "fmt"
1919 "strconv"
20- "sync"
2120 "testing"
2221 "time"
2322
@@ -29,6 +28,7 @@ import (
2928 "github.com/firecracker-microvm/firecracker-containerd/runtime/firecrackeroci"
3029 "github.com/firecracker-microvm/firecracker-containerd/snapshotter/internal/integtest/stargz/fs/source"
3130 "github.com/stretchr/testify/require"
31+ "golang.org/x/sync/errgroup"
3232)
3333
3434const (
@@ -58,7 +58,8 @@ func TestLaunchContainerWithRemoteSnapshotter_Isolated(t *testing.T) {
5858 ctx , cancel := context .WithTimeout (context .Background (), testTimeout )
5959 defer cancel ()
6060
61- launchContainerWithRemoteSnapshotterInVM (ctx , t , strconv .Itoa (vmID ))
61+ err := launchContainerWithRemoteSnapshotterInVM (ctx , strconv .Itoa (vmID ))
62+ require .NoError (t , err )
6263}
6364
6465func TestLaunchMultipleContainersWithRemoteSnapshotter_Isolated (t * testing.T ) {
@@ -68,30 +69,35 @@ func TestLaunchMultipleContainersWithRemoteSnapshotter_Isolated(t *testing.T) {
6869 ctx , cancel := context .WithTimeout (context .Background (), testTimeout )
6970 defer cancel ()
7071
71- var wg sync. WaitGroup
72+ eg , ctx := errgroup . WithContext ( ctx )
7273
7374 numberOfVms := integtest .NumberOfVms
7475 for vmID := 0 ; vmID < numberOfVms ; vmID ++ {
75- wg . Add ( 1 )
76- go func ( id int ) {
77- defer wg . Done ()
78- launchContainerWithRemoteSnapshotterInVM (ctx , t , strconv .Itoa (id ))
79- }( vmID )
76+ ctx := ctx
77+ id := vmID
78+ eg . Go ( func () error {
79+ return launchContainerWithRemoteSnapshotterInVM (ctx , strconv .Itoa (id ))
80+ })
8081 }
81- wg .Wait ()
82+ err := eg .Wait ()
83+ require .NoError (t , err )
8284}
8385
84- func launchContainerWithRemoteSnapshotterInVM (ctx context.Context , t * testing. T , vmID string ) {
86+ func launchContainerWithRemoteSnapshotterInVM (ctx context.Context , vmID string ) error {
8587 // For integration testing, assume the namespace is same as the VM ID.
8688 namespace := vmID
8789
8890 ctx = namespaces .WithNamespace (ctx , namespace )
8991
9092 client , err := containerd .New (integtest .ContainerdSockPath , containerd .WithDefaultRuntime (integtest .FirecrackerRuntime ))
91- require .NoError (t , err , "Unable to create client to containerd service at %s, is containerd running?" , integtest .ContainerdSockPath )
93+ if err != nil {
94+ return fmt .Errorf ("Unable to create client to containerd service at %s, is containerd running? [%v]" , integtest .ContainerdSockPath , err )
95+ }
9296
9397 fcClient , err := integtest .NewFCControlClient (integtest .ContainerdSockPath )
94- require .NoError (t , err , "Failed to create fccontrol client" )
98+ if err != nil {
99+ return fmt .Errorf ("Failed to create fccontrol client. [%v]" , err )
100+ }
95101
96102 _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
97103 VMID : vmID ,
@@ -113,21 +119,27 @@ func launchContainerWithRemoteSnapshotterInVM(ctx context.Context, t *testing.T,
113119 },
114120 ContainerCount : 1 ,
115121 })
116- require .NoErrorf (t , err , "Failed to create microVM[%s]" , vmID )
122+ if err != nil {
123+ return fmt .Errorf ("Failed to create microVM[%s] [%v]" , vmID , err )
124+ }
117125 defer fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : vmID })
118126
119127 _ , err = fcClient .SetVMMetadata (ctx , & proto.SetVMMetadataRequest {
120128 VMID : vmID ,
121129 Metadata : fmt .Sprintf (dockerMetadataTemplate , "ghcr.io" , noAuth , noAuth ),
122130 })
123- require .NoError (t , err , "Failed to configure VM metadata for registry resolution" )
131+ if err != nil {
132+ return fmt .Errorf ("Failed to configure VM metadata for registry resolution [%v]" , err )
133+ }
124134
125135 image , err := client .Pull (ctx , imageRef ,
126136 containerd .WithPullUnpack ,
127137 containerd .WithPullSnapshotter (snapshotterName ),
128138 containerd .WithImageHandlerWrapper (source .AppendDefaultLabelsHandlerWrapper (imageRef , 10 * 1024 * 1024 )),
129139 )
130- require .NoError (t , err , "Failed to pull image for VM: %s" , vmID )
140+ if err != nil {
141+ return fmt .Errorf ("Failed to pull image for VM: %s [%v]" , vmID , err )
142+ }
131143 defer client .ImageService ().Delete (ctx , image .Name ())
132144
133145 container , err := client .NewContainer (ctx , fmt .Sprintf ("container-%s" , vmID ),
@@ -141,9 +153,14 @@ func launchContainerWithRemoteSnapshotterInVM(ctx context.Context, t *testing.T,
141153 firecrackeroci .WithVMNetwork ,
142154 ),
143155 )
144- require .NoError (t , err , "Failed to create container in VM: %s" , vmID )
156+ if err != nil {
157+ return fmt .Errorf ("Failed to create container in VM: %s, [%v]" , vmID , err )
158+ }
145159 defer container .Delete (ctx , containerd .WithSnapshotCleanup )
146160
147161 _ , err = integtest .RunTask (ctx , container )
148- require .NoError (t , err , "Failed to run task in VM: %s" , vmID )
162+ if err != nil {
163+ return fmt .Errorf ("Failed to run task in VM: %s [%v]" , vmID , err )
164+ }
165+ return nil
149166}
0 commit comments