Skip to content

Commit eb7eaf1

Browse files
authored
Merge pull request #5256 from kolyshkin/int-hook
Fix flakiness in TestHook
2 parents 543ef45 + 1d12f98 commit eb7eaf1

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

libcontainer/integration/exec_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ func TestPassExtraFiles(t *testing.T) {
784784
ExtraFiles: []*os.File{pipein1, pipein2},
785785
Stdin: nil,
786786
Stdout: &stdout,
787+
Stderr: new(strings.Builder),
787788
Init: true,
788789
}
789790
err = container.Run(&process)
@@ -1074,11 +1075,14 @@ func TestHook(t *testing.T) {
10741075
container, err := newContainer(t, config)
10751076
ok(t, err)
10761077

1077-
// e.g: 'ls /prestart ...'
10781078
var cmd strings.Builder
10791079
cmd.WriteString("ls ")
10801080
for _, hook := range hookFiles {
1081-
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+
}
10821086
}
10831087

10841088
var stdout strings.Builder
@@ -1097,6 +1101,13 @@ func TestHook(t *testing.T) {
10971101
// Wait for process
10981102
waitProcess(&pconfig, t)
10991103

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+
11001111
if err := container.Destroy(); err != nil {
11011112
t.Fatalf("container destroy %s", err)
11021113
}

libcontainer/integration/execin_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ func TestExecinPassExtraFiles(t *testing.T) {
421421
ExtraFiles: []*os.File{pipein1, pipein2},
422422
Stdin: nil,
423423
Stdout: &stdout,
424+
Stderr: new(strings.Builder),
424425
}
425426
err = container.Run(inprocess)
426427
ok(t, err)

0 commit comments

Comments
 (0)