Skip to content

Commit 82deb40

Browse files
committed
*: stop leaking (most) etcd procs
The majority of usages of `RedpandaTestEnv` leak `etcd` and `kube-apiserver` processes. This slowly bogs down machines running tests as part of their development loop. The ideal fix would be to plumb a testing.T into it and hook into cleanup but the widespread usage makes refactoring quite tedious. This commit instead attaches a finalizer to the returned `*rest.Config` which drops the leaked procs by > 50% (~10 leaks vs ~30). The leakage will vary across runs and is made worse by test failures. Never the less this is an improvement.
1 parent ab440ae commit 82deb40

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

operator/internal/testutils/setup_envtest.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ func (e *RedpandaTestEnv) StartRedpandaTestEnv(withWebhook bool) (*rest.Config,
4343
Paths: []string{filepath.Join(configPath, "webhook")},
4444
}
4545
}
46+
4647
cfg, err := e.Start()
48+
if err != nil {
49+
return nil, err
50+
}
51+
52+
// Ideally we'd plumb in testing.T here to ensure that clean up is run.
53+
// This seems to run ~80% of the time which is a dramatic improvement.
54+
runtime.AddCleanup(cfg, func(e *RedpandaTestEnv) {
55+
_ = e.Stop()
56+
}, e)
57+
4758
return cfg, err
4859
}
4960

pkg/kube/envexpander_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func TestEnvExpander(t *testing.T) {
2828
cfg, err := env.Start()
2929
require.NoError(t, err)
3030

31+
t.Cleanup(func() { _ = env.Stop() })
32+
3133
c, err := client.New(cfg, client.Options{})
3234
require.NoError(t, err)
3335

0 commit comments

Comments
 (0)