@@ -17,7 +17,6 @@ import (
17
17
"context"
18
18
"fmt"
19
19
"strconv"
20
- "sync"
21
20
"testing"
22
21
"time"
23
22
@@ -29,6 +28,7 @@ import (
29
28
"github.com/firecracker-microvm/firecracker-containerd/runtime/firecrackeroci"
30
29
"github.com/firecracker-microvm/firecracker-containerd/snapshotter/internal/integtest/stargz/fs/source"
31
30
"github.com/stretchr/testify/require"
31
+ "golang.org/x/sync/errgroup"
32
32
)
33
33
34
34
const (
@@ -58,7 +58,8 @@ func TestLaunchContainerWithRemoteSnapshotter_Isolated(t *testing.T) {
58
58
ctx , cancel := context .WithTimeout (context .Background (), testTimeout )
59
59
defer cancel ()
60
60
61
- launchContainerWithRemoteSnapshotterInVM (ctx , t , strconv .Itoa (vmID ))
61
+ err := launchContainerWithRemoteSnapshotterInVM (ctx , strconv .Itoa (vmID ))
62
+ require .NoError (t , err )
62
63
}
63
64
64
65
func TestLaunchMultipleContainersWithRemoteSnapshotter_Isolated (t * testing.T ) {
@@ -68,30 +69,35 @@ func TestLaunchMultipleContainersWithRemoteSnapshotter_Isolated(t *testing.T) {
68
69
ctx , cancel := context .WithTimeout (context .Background (), testTimeout )
69
70
defer cancel ()
70
71
71
- var wg sync. WaitGroup
72
+ eg , ctx := errgroup . WithContext ( ctx )
72
73
73
74
numberOfVms := integtest .NumberOfVms
74
75
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
+ })
80
81
}
81
- wg .Wait ()
82
+ err := eg .Wait ()
83
+ require .NoError (t , err )
82
84
}
83
85
84
- func launchContainerWithRemoteSnapshotterInVM (ctx context.Context , t * testing. T , vmID string ) {
86
+ func launchContainerWithRemoteSnapshotterInVM (ctx context.Context , vmID string ) error {
85
87
// For integration testing, assume the namespace is same as the VM ID.
86
88
namespace := vmID
87
89
88
90
ctx = namespaces .WithNamespace (ctx , namespace )
89
91
90
92
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
+ }
92
96
93
97
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
+ }
95
101
96
102
_ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
97
103
VMID : vmID ,
@@ -113,21 +119,27 @@ func launchContainerWithRemoteSnapshotterInVM(ctx context.Context, t *testing.T,
113
119
},
114
120
ContainerCount : 1 ,
115
121
})
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
+ }
117
125
defer fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : vmID })
118
126
119
127
_ , err = fcClient .SetVMMetadata (ctx , & proto.SetVMMetadataRequest {
120
128
VMID : vmID ,
121
129
Metadata : fmt .Sprintf (dockerMetadataTemplate , "ghcr.io" , noAuth , noAuth ),
122
130
})
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
+ }
124
134
125
135
image , err := client .Pull (ctx , imageRef ,
126
136
containerd .WithPullUnpack ,
127
137
containerd .WithPullSnapshotter (snapshotterName ),
128
138
containerd .WithImageHandlerWrapper (source .AppendDefaultLabelsHandlerWrapper (imageRef , 10 * 1024 * 1024 )),
129
139
)
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
+ }
131
143
defer client .ImageService ().Delete (ctx , image .Name ())
132
144
133
145
container , err := client .NewContainer (ctx , fmt .Sprintf ("container-%s" , vmID ),
@@ -141,9 +153,14 @@ func launchContainerWithRemoteSnapshotterInVM(ctx context.Context, t *testing.T,
141
153
firecrackeroci .WithVMNetwork ,
142
154
),
143
155
)
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
+ }
145
159
defer container .Delete (ctx , containerd .WithSnapshotCleanup )
146
160
147
161
_ , 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
149
166
}
0 commit comments