Skip to content

Commit 7d825b2

Browse files
Add test for cgroups load when missing hierarchy in one subsystem
Signed-off-by: MichaelKatsoulis <[email protected]>
1 parent f6cbfb4 commit 7d825b2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

cgroup_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ func checkTaskid(mock *mockCgroup, path string, expected int) error {
197197
return nil
198198
}
199199

200+
func mockNewNotInRdma(subsystems []Subsystem, path Path, resources *specs.LinuxResources) (Cgroup, error) {
201+
for _, s := range subsystems {
202+
if s.Name() != Rdma {
203+
if err := initializeSubsystem(s, path, resources); err != nil {
204+
return nil, err
205+
}
206+
}
207+
}
208+
return &cgroup{
209+
path: path,
210+
subsystems: subsystems,
211+
}, nil
212+
}
213+
200214
func TestLoad(t *testing.T) {
201215
mock, err := newMock()
202216
if err != nil {
@@ -218,6 +232,36 @@ func TestLoad(t *testing.T) {
218232
}
219233
}
220234

235+
func TestLoadWithMissingSubsystems(t *testing.T) {
236+
mock, err := newMock()
237+
if err != nil {
238+
t.Fatal(err)
239+
}
240+
defer mock.delete()
241+
subsystems, err := mock.hierarchy()
242+
if err != nil {
243+
t.Error(err)
244+
return
245+
}
246+
control, err := mockNewNotInRdma(subsystems, StaticPath("test"), &specs.LinuxResources{})
247+
if err != nil {
248+
t.Error(err)
249+
return
250+
}
251+
if control, err = Load(mock.hierarchy, StaticPath("test")); err != nil {
252+
t.Error(err)
253+
return
254+
}
255+
if control == nil {
256+
t.Error("control is nil")
257+
return
258+
}
259+
if len(control.Subsystems()) != len(subsystems) - 1 {
260+
t.Error("wrong number of active subsystems")
261+
return
262+
}
263+
}
264+
221265
func TestDelete(t *testing.T) {
222266
mock, err := newMock()
223267
if err != nil {

0 commit comments

Comments
 (0)