Skip to content

Commit

Permalink
cgroup: improve test to find cgroup compatibility issues (#41347)
Browse files Browse the repository at this point in the history
close #39786
  • Loading branch information
hawkingrei committed Feb 13, 2023
1 parent 534bd02 commit 95c5328
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 95c5328

Please sign in to comment.