Skip to content

Commit 1d12f98

Browse files
committed
tests/int: fix TestHook flakiness
Since commit 3cdda46 the poststart hooks runs after the container process start, and so they race. Move the poststart hook check to a separate step after the container process has exited. Fixes 5245. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 905958e commit 1d12f98

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

libcontainer/integration/exec_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,11 +1075,14 @@ func TestHook(t *testing.T) {
10751075
container, err := newContainer(t, config)
10761076
ok(t, err)
10771077

1078-
// e.g: 'ls /prestart ...'
10791078
var cmd strings.Builder
10801079
cmd.WriteString("ls ")
10811080
for _, hook := range hookFiles {
1082-
cmd.WriteString("/" + hook + " ")
1081+
// The poststart hook is racing with this ls command (run as the
1082+
// container init), so we don't check that hook worked here yet.
1083+
if hook != "poststart" {
1084+
cmd.WriteString("/" + hook + " ")
1085+
}
10831086
}
10841087

10851088
var stdout strings.Builder
@@ -1098,6 +1101,13 @@ func TestHook(t *testing.T) {
10981101
// Wait for process
10991102
waitProcess(&pconfig, t)
11001103

1104+
// Check that poststart hook worked.
1105+
f, err = os.Open(config.Rootfs + "/poststart")
1106+
if err != nil {
1107+
t.Fatalf("poststart hook failed: %s", err)
1108+
}
1109+
f.Close()
1110+
11011111
if err := container.Destroy(); err != nil {
11021112
t.Fatalf("container destroy %s", err)
11031113
}

0 commit comments

Comments
 (0)