Skip to content

Commit

Permalink
libct/int/TestFreeze: test freeze/thaw via Set
Browse files Browse the repository at this point in the history
In addition to freezing and thawing a container via Pause/Resume,
there is a way to also do so via Set.

This way was broken though and is being fixed by a few preceding
commits. The test is added to make sure this is fixed and won't regress.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jul 15, 2021
1 parent af1688a commit 5dc3260
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,28 +493,41 @@ func TestAdditionalGroups(t *testing.T) {
}

func TestFreeze(t *testing.T) {
testFreeze(t, false)
}

func TestSystemdFreeze(t *testing.T) {
if !systemd.IsRunningSystemd() {
t.Skip("Test requires systemd.")
for _, systemd := range []bool{true, false} {
for _, set := range []bool{true, false} {
name := ""
if systemd {
name += "Systemd"
} else {
name += "FS"
}
if set {
name += "ViaSet"
} else {
name += "ViaPauseResume"
}
t.Run(name, func(t *testing.T) {
testFreeze(t, systemd, set)
})
}
}
testFreeze(t, true)
}

func testFreeze(t *testing.T, systemd bool) {
func testFreeze(t *testing.T, withSystemd bool, useSet bool) {
if testing.Short() {
return
}
if withSystemd && !systemd.IsRunningSystemd() {
t.Skip("Test requires systemd.")
}

rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)

config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
systemd: systemd,
systemd: withSystemd,
})
container, err := newContainer(t, config)
ok(t, err)
Expand All @@ -535,16 +548,28 @@ func testFreeze(t *testing.T, systemd bool) {
defer stdinW.Close() //nolint: errcheck
ok(t, err)

err = container.Pause()
if !useSet {
err = container.Pause()
} else {
config.Cgroups.Resources.Freezer = configs.Frozen
err = container.Set(*config)
}
ok(t, err)

state, err := container.Status()
ok(t, err)
err = container.Resume()
ok(t, err)
if state != libcontainer.Paused {
t.Fatal("Unexpected state: ", state)
}

if !useSet {
err = container.Resume()
} else {
config.Cgroups.Resources.Freezer = configs.Thawed
err = container.Set(*config)
}
ok(t, err)

_ = stdinW.Close()
waitProcess(pconfig, t)
}
Expand Down

0 comments on commit 5dc3260

Please sign in to comment.