mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
ci: fix TestNilResources when systemd not available
Split the test into two -- for fs and systemd cgroup managers, and only run the second one if systemd is available. Prevents the following failure during `make unittest`: > === RUN TestNilResources > manager_test.go:27: systemd not running on this host, cannot use systemd cgroups manager > --- FAIL: TestNilResources (0.22s) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package manager
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
||||
"github.com/opencontainers/runc/libcontainer/configs"
|
||||
)
|
||||
|
||||
@@ -10,35 +11,45 @@ import (
|
||||
// config.Resources is nil. While it does not make sense to use a
|
||||
// manager with no resources, it should not result in a panic.
|
||||
//
|
||||
// This tests either v1 or v2 managers (both fs and systemd),
|
||||
// depending on what cgroup version is available on the host.
|
||||
// This tests either v1 or v2 fs cgroup manager, depending on which
|
||||
// cgroup version is available.
|
||||
func TestNilResources(t *testing.T) {
|
||||
for _, sd := range []bool{false, true} {
|
||||
cg := &configs.Cgroup{} // .Resources is nil
|
||||
cg.Systemd = sd
|
||||
mgr, err := New(cg)
|
||||
if err != nil {
|
||||
// Some managers require non-nil Resources during
|
||||
// instantiation -- provide and retry. In such case
|
||||
// we're mostly testing Set(nil) below.
|
||||
cg.Resources = &configs.Resources{}
|
||||
mgr, err = New(cg)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
_ = mgr.Apply(-1)
|
||||
_ = mgr.Set(nil)
|
||||
_ = mgr.Freeze(configs.Thawed)
|
||||
_ = mgr.Exists()
|
||||
_, _ = mgr.GetAllPids()
|
||||
_, _ = mgr.GetCgroups()
|
||||
_, _ = mgr.GetFreezerState()
|
||||
_ = mgr.Path("")
|
||||
_ = mgr.GetPaths()
|
||||
_, _ = mgr.GetStats()
|
||||
_, _ = mgr.OOMKillCount()
|
||||
_ = mgr.Destroy()
|
||||
}
|
||||
testNilResources(t, false)
|
||||
}
|
||||
|
||||
// TestNilResourcesSystemd is the same as TestNilResources,
|
||||
// only checking the systemd cgroup manager.
|
||||
func TestNilResourcesSystemd(t *testing.T) {
|
||||
if !systemd.IsRunningSystemd() {
|
||||
t.Skip("requires systemd")
|
||||
}
|
||||
testNilResources(t, true)
|
||||
}
|
||||
|
||||
func testNilResources(t *testing.T, systemd bool) {
|
||||
cg := &configs.Cgroup{} // .Resources is nil
|
||||
cg.Systemd = systemd
|
||||
mgr, err := New(cg)
|
||||
if err != nil {
|
||||
// Some managers require non-nil Resources during
|
||||
// instantiation -- provide and retry. In such case
|
||||
// we're mostly testing Set(nil) below.
|
||||
cg.Resources = &configs.Resources{}
|
||||
mgr, err = New(cg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
_ = mgr.Apply(-1)
|
||||
_ = mgr.Set(nil)
|
||||
_ = mgr.Freeze(configs.Thawed)
|
||||
_ = mgr.Exists()
|
||||
_, _ = mgr.GetAllPids()
|
||||
_, _ = mgr.GetCgroups()
|
||||
_, _ = mgr.GetFreezerState()
|
||||
_ = mgr.Path("")
|
||||
_ = mgr.GetPaths()
|
||||
_, _ = mgr.GetStats()
|
||||
_, _ = mgr.OOMKillCount()
|
||||
_ = mgr.Destroy()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user