diff options
| author | Shulhan <m.shulhan@gmail.com> | 2026-03-28 21:55:51 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2026-04-14 21:51:40 +0700 |
| commit | f0eca1afc2477dfcf0f17078e902e59956af63c2 (patch) | |
| tree | 5bd2f30b1632204525b5b8052f9a6a1be7e760ee | |
| parent | fe96b7709cf3411c5dd65bd7f1534d1290f55447 (diff) | |
| download | go-f0eca1afc2477dfcf0f17078e902e59956af63c2.tar.xz | |
internal/cgrouptest: use t.Cleanup instead of defer in InCgroupV2
Using defer may cause the TestCgroupGOMAXPROCS fail with the following
error messages,
--- FAIL: TestCgroupGOMAXPROCS (5.14s)
crash_test.go:193: running /home/ms/src/go/bin/go build -o /tmp/go-build2154548206/testprog.exe
crash_test.go:216: built testprog in 5.13507196s
--- FAIL: TestCgroupGOMAXPROCS/containermaxprocs=0 (0.00s)
cgroup_linux_test.go:60: /tmp/go-build2154548206/testprog.exe PrintGOMAXPROCS (1.191505ms): ok
cgrouptest_linux.go:81: Error removing cgroup directory: remove /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/go-cgrouptest4138918176: device or resource busy
Under the following environment,
- Linux 6.19.9-arch1-1 #1 SMP PREEMPT_DYNAMIC
- systemd 260 (260.1-1-arch)
Change-Id: Ic36b0b98f0d589ea5730ea35097af04a22dc7469
| -rw-r--r-- | src/internal/cgrouptest/cgrouptest_linux.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/internal/cgrouptest/cgrouptest_linux.go b/src/internal/cgrouptest/cgrouptest_linux.go index ad9599c938..72380debc6 100644 --- a/src/internal/cgrouptest/cgrouptest_linux.go +++ b/src/internal/cgrouptest/cgrouptest_linux.go @@ -74,16 +74,16 @@ func InCgroupV2(t *testing.T, fn func(*CgroupV2)) { // // TODO(prattmic): Consider running everything in a subprocess just so // we can clean up if it throws or otherwise doesn't run the defers. - defer func() { + t.Cleanup(func() { if err := os.Remove(path); err != nil { // Not much we can do, but at least inform of the // problem. t.Errorf("Error removing cgroup directory: %v", err) } - }() + }) migrateTo(t, path) - defer migrateTo(t, orig) + t.Cleanup(func() { migrateTo(t, orig) }) c := &CgroupV2{ orig: orig, |
