Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 42 additions & 34 deletions test/e2e/run_signal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"
"strings"
"syscall"
"time"

"github.com/onsi/gomega/gexec"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -54,48 +55,55 @@ var _ = Describe("Podman run with --sig-proxy", func() {

Specify("signals are forwarded to container using sig-proxy", func() {
signal := syscall.SIGPOLL
session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test1", fedoraMinimal, "bash", "-c", sigCatch})

ok := WaitForContainer(&podmanTest)
Expect(ok).To(BeTrue())

// Kill with given signal
if err := unix.Kill(pid, signal); err != nil {
Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
session, pid := podmanTest.PodmanPID([]string{"run", "-it", "--name", "test1", fedoraMinimal, "bash", "-c", sigCatch})
for i := 0; i < 10; i++ {
foo := podmanTest.Podman([]string{"ps", "-q", "--filter", "name=test1"})
foo.WaitWithDefaultTimeout()
if len(foo.OutputToStringArray()) == 1 && foo.OutputToString() != "" {
break
}
time.Sleep(1 * time.Second)
}

// Kill with given signal and do it 5 times because this stuff is racey!
for j := 0; j < 5; j++ {
if err := unix.Kill(pid, signal); err != nil {
Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
}
time.Sleep(5)
}
// Kill with -9 to guarantee the container dies
killSession := podmanTest.Podman([]string{"kill", "-s", "9", "test1"})
killSession.WaitWithDefaultTimeout()
Expect(killSession.ExitCode()).To(Equal(0))

session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
ok, _ = session.GrepString(fmt.Sprintf("Received %d", signal))
Expect(ok).To(BeTrue())
})

Specify("signals are not forwarded to container with sig-proxy false", func() {
signal := syscall.SIGPOLL
session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test2", "--sig-proxy=false", fedoraMinimal, "bash", "-c", sigCatch})

ok := WaitForContainer(&podmanTest)
ok, _ := session.GrepString(fmt.Sprintf("Received %d", signal))
Expect(ok).To(BeTrue())

// Kill with given signal
// Should be no output, SIGPOLL is usually ignored
if err := unix.Kill(pid, signal); err != nil {
Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
}

// Kill with -9 to guarantee the container dies
killSession := podmanTest.Podman([]string{"kill", "-s", "9", "test2"})
killSession.WaitWithDefaultTimeout()
Expect(killSession.ExitCode()).To(Equal(0))

session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
ok, _ = session.GrepString(fmt.Sprintf("Received %d", signal))
Expect(ok).To(BeFalse())
})
/*
Specify("signals are not forwarded to container with sig-proxy false", func() {
signal := syscall.SIGPOLL
session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test2", "--sig-proxy=false", fedoraMinimal, "bash", "-c", sigCatch})

ok := WaitForContainer(&podmanTest)
Expect(ok).To(BeTrue())

// Kill with given signal
// Should be no output, SIGPOLL is usually ignored
if err := unix.Kill(pid, signal); err != nil {
Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
}

// Kill with -9 to guarantee the container dies
killSession := podmanTest.Podman([]string{"kill", "-s", "9", "test2"})
killSession.WaitWithDefaultTimeout()
Expect(killSession.ExitCode()).To(Equal(0))

session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
ok, _ = session.GrepString(fmt.Sprintf("Received %d", signal))
Expect(ok).To(BeFalse())
})
*/
})