5d5c8af930
This PR refactors the cgroups v2 group kill code path to use the cgroups.kill interface file for destroying the cgroup. Previously we copied the freeze + sigkill + unfreeze pattern from the v1 code, but v2 provides a more efficient and more race-free way to handle this. Closes #14371
40 lines
728 B
Go
40 lines
728 B
Go
//go:build linux
|
|
|
|
package cgutil
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/nomad/client/testutil"
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
"github.com/shoenig/test/must"
|
|
)
|
|
|
|
func createCG(t *testing.T) (string, func()) {
|
|
name := uuid.Short() + ".scope"
|
|
path := filepath.Join(CgroupRoot, name)
|
|
err := os.Mkdir(path, 0o755)
|
|
must.NoError(t, err)
|
|
|
|
return name, func() {
|
|
_ = os.Remove(path)
|
|
}
|
|
}
|
|
|
|
func TestCG_editor(t *testing.T) {
|
|
testutil.CgroupsCompatibleV2(t)
|
|
|
|
cg, rm := createCG(t)
|
|
t.Cleanup(rm)
|
|
|
|
edits := &editor{cg}
|
|
writeErr := edits.write("cpu.weight.nice", "13")
|
|
must.NoError(t, writeErr)
|
|
|
|
b, readErr := edits.read("cpu.weight.nice")
|
|
must.NoError(t, readErr)
|
|
must.Eq(t, "13", b)
|
|
}
|