*: modernize: waitgroup

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn committed 2026-03-17 13:36:17 +01:00
1 parent 24012ef8f6
commit 9bdcacc45f
9 files changed
+24 -48

No files matched your search

+2 -4
View File
@@ -94,10 +94,8 @@ func TestRegressionIssue6772(t *testing.T) {
var wg sync.WaitGroup
for i := range maxItem {
id := i
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
err := collector.Add(
&mockStatT{
@@ -110,7 +108,7 @@ func TestRegressionIssue6772(t *testing.T) {
if err != nil {
errCh <- err
}
}()
})
}
finishedCh := make(chan struct{})
+2 -4
View File
@@ -71,8 +71,7 @@ func openShimLog(ctx context.Context, bundle *Bundle, dialer func(string, time.D
dpc := &deferredPipeConnection{
ctx: ctx,
}
dpc.wg.Add(1)
go func() {
dpc.wg.Go(func() {
c, conerr := dialer(
fmt.Sprintf("\\\\.\\pipe\\containerd-shim-%s-%s-log", ns, bundle.ID),
time.Second*10,
@@ -81,8 +80,7 @@ func openShimLog(ctx context.Context, bundle *Bundle, dialer func(string, time.D
dpc.conerr = fmt.Errorf("failed to connect to shim log: %w", conerr)
}
dpc.c = c
dpc.wg.Done()
}()
})
return dpc, nil
}
@@ -119,11 +119,9 @@ func TestCheckpointRestorePTY(t *testing.T) {
wg sync.WaitGroup
buf = bytes.NewBuffer(nil)
)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
io.Copy(buf, direct.Stdout)
}()
})
if container, err = client.Restore(ctx, id, checkpoint, []RestoreOpts{
WithRestoreImage,
+8 -16
View File
@@ -528,11 +528,9 @@ func TestContainerAttach(t *testing.T) {
wg sync.WaitGroup
buf = bytes.NewBuffer(nil)
)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
io.Copy(buf, direct.Stdout)
}()
})
task, err := container.NewTask(ctx, direct.IOCreate)
if err != nil {
@@ -623,11 +621,9 @@ func testContainerUser(t *testing.T, userstr, expectedOutput string) {
wg sync.WaitGroup
buf = bytes.NewBuffer(nil)
)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
io.Copy(buf, direct.Stdout)
}()
})
container, err := client.NewContainer(ctx, id,
WithNewSnapshot(id, image),
@@ -701,11 +697,9 @@ func TestContainerAttachProcess(t *testing.T) {
wg sync.WaitGroup
buf = bytes.NewBuffer(nil)
)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
io.Copy(buf, direct.Stdout)
}()
})
task, err := container.NewTask(ctx, empty())
if err != nil {
@@ -872,11 +866,9 @@ func TestContainerUserID(t *testing.T) {
wg sync.WaitGroup
buf = bytes.NewBuffer(nil)
)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
io.Copy(buf, direct.Stdout)
}()
})
// sys user in the busybox image has a uid and gid of 3.
container, err := client.NewContainer(ctx, id,
@@ -159,11 +159,9 @@ func TestMountAtRuntime(t *testing.T) {
wg sync.WaitGroup
buf = bytes.NewBuffer(nil)
)
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
io.Copy(buf, direct.Stdout)
}()
})
task, err = container2.NewTask(ctx, direct.IOCreate, containerd.WithRootFS(m))
require.NoError(t, err)
+2 -4
View File
@@ -93,9 +93,7 @@ version = 3
t.Logf("Creating %d running container and wait for them OOMKilled", n)
var wg sync.WaitGroup
for _, podCtx := range podCtxs {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
cntrID := podCtx.createContainer(fmt.Sprintf("round-%d-running", round), busyboxImage,
criruntime.ContainerState_CONTAINER_RUNNING,
@@ -134,7 +132,7 @@ version = 3
}, time.Second, 90*time.Second), "wait for container %s to exit", cntrID)
assert.NoError(t, ctrd.criRuntimeService(t).RemoveContainer(cntrID), "failed to remove container %s", cntrID)
}()
})
}
wg.Wait()
}
+2 -4
View File
@@ -149,14 +149,12 @@ func TestSandboxStopWithNilCNIResult(t *testing.T) {
injectCNIFailpoint(t, sbConfig, conf)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
t.Log("Create a sandbox (will hang on CNI Add)")
_, err := runtimeService.RunPodSandbox(sbConfig, failpointRuntimeHandler)
assert.Error(t, err)
}()
})
t.Log("Wait for CNI Add to start running")
assert.NoError(t, ensureCNIAddRunning(t, sbName), "CNI Add should be running")
+2 -4
View File
@@ -256,15 +256,13 @@ func TestRunPodSandboxAndTeardownCNISlow(t *testing.T) {
injectCNIFailpoint(t, sbConfig, conf)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
t.Log("Create a sandbox")
_, err := runtimeService.RunPodSandbox(sbConfig, failpointRuntimeHandler)
require.Error(t, err)
require.ErrorContains(t, err, "error reading from server: EOF")
}()
})
assert.NoError(t, ensureCNIAddRunning(t, sbName), "check that failpoint CNI.Add is running")
+2 -4
View File
@@ -40,16 +40,14 @@ func openPipe(ctx context.Context, fn string, flag int, perm os.FileMode) (io.Re
return nil, err
}
p := &pipe{l: l}
p.conWg.Add(1)
go func() {
defer p.conWg.Done()
p.conWg.Go(func() {
c, err := l.Accept()
if err != nil {
p.conErr = err
return
}
p.con = c
}()
})
go func() {
<-ctx.Done()
p.Close()