Skip to content

Commit

Permalink
cgroup: improve test to find cgroup compatibility issues (pingcap#41347)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored and blacktear23 committed Feb 15, 2023
1 parent 546d30d commit afdfe39
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion util/cgroup/cgroup_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/pingcap/errors"
)

var errNoCPUControllerDetected = errors.New("no cpu controller detected")

// Helper function for getCgroupCPU. Root is always "/", except in tests.
func getCgroupCPU(root string) (CPUUsage, error) {
path, err := detectControlPath(filepath.Join(root, procPathCGroup), "cpu,cpuacct")
Expand All @@ -30,7 +32,7 @@ func getCgroupCPU(root string) (CPUUsage, error) {

// No CPU controller detected
if path == "" {
return CPUUsage{}, errors.New("no cpu controller detected")
return CPUUsage{}, errNoCPUControllerDetected
}

mount, ver, err := getCgroupDetails(filepath.Join(root, procPathMountInfo), path, "cpu,cpuacct")
Expand Down
10 changes: 7 additions & 3 deletions util/cgroup/cgroup_cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ func TestGetCgroupCPU(t *testing.T) {
}()
}
cpu, err := GetCgroupCPU()
require.NoError(t, err)
require.NotZero(t, cpu.Period)
require.Less(t, int64(1), cpu.Period)
if err == errNoCPUControllerDetected {
require.False(t, InContainer(), "Please check linux version > v4.7.x. This is related to cgroup compatibility.")
} else {
require.NoError(t, err)
require.NotZero(t, cpu.Period)
require.Less(t, int64(1), cpu.Period)
}
close(exit)
wg.Wait()
}

0 comments on commit afdfe39

Please sign in to comment.