libct/cg/dev: add sync.Once to test case

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2023-10-10 13:27:22 -07:00
parent fa8f38171c
commit bdf78b446b
+15 -2
View File
@@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"strings"
"sync"
"testing"
"github.com/opencontainers/runc/libcontainer/cgroups"
@@ -117,11 +118,23 @@ func TestPodSkipDevicesUpdate(t *testing.T) {
}
}
var (
centosVer string
centosVerOnce sync.Once
)
func centosVersion() string {
centosVerOnce.Do(func() {
ver, _ := exec.Command("rpm", "-q", "--qf", "%{version}", "centos-release").CombinedOutput()
centosVer = string(ver)
})
return centosVer
}
func skipOnCentOS7(t *testing.T) {
t.Helper()
// https://github.com/opencontainers/runc/issues/3743
centosVer, _ := exec.Command("rpm", "-q", "--qf", "%{version}", "centos-release").CombinedOutput()
if string(centosVer) == "7" {
if centosVersion() == "7" {
t.Skip("Flaky on CentOS 7")
}
}