Eliminate raceyness of sig-proxy test

Use a socket to coordinate between the test suite and the container and its
script.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #567
Approved by: rhatdan
This commit is contained in:
baude
2018-03-28 13:08:55 -05:00
committed by Atomic Bot
parent ae43ce00fe
commit 03ec980dcf

View File

@ -2,16 +2,18 @@ package integration
import ( import (
"fmt" "fmt"
"io"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"strings" "strings"
"syscall" "syscall"
"time"
"github.com/onsi/gomega/gexec"
"golang.org/x/sys/unix"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"golang.org/x/sys/unix"
) )
// PodmanPID execs podman and returns its PID // PodmanPID execs podman and returns its PID
@ -28,7 +30,7 @@ func (p *PodmanTest) PodmanPID(args []string) (*PodmanSession, int) {
return &PodmanSession{session}, command.Process.Pid return &PodmanSession{session}, command.Process.Pid
} }
const sigCatch = "for NUM in `seq 1 64`; do trap \"echo Received $NUM\" $NUM; done; echo READY; while :; do sleep 0.1; done" const sigCatch = "trap \"echo FOO >> /h/fifo \" 8; echo READY >> /h/fifo; while :; do sleep 0.25; done"
var _ = Describe("Podman run with --sig-proxy", func() { var _ = Describe("Podman run with --sig-proxy", func() {
var ( var (
@ -53,27 +55,63 @@ var _ = Describe("Podman run with --sig-proxy", func() {
}) })
Specify("signals are forwarded to container using sig-proxy", func() { Specify("signals are forwarded to container using sig-proxy", func() {
Skip("Race condition issues on CI seem unfixable") signal := syscall.SIGFPE
signal := syscall.SIGPOLL // Set up a socket for communication
session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test1", fedoraMinimal, "bash", "-c", sigCatch}) udsDir := filepath.Join(tmpdir, "socket")
os.Mkdir(udsDir, 0700)
udsPath := filepath.Join(udsDir, "fifo")
syscall.Mkfifo(udsPath, 0600)
ok := WaitForContainer(&podmanTest) _, pid := podmanTest.PodmanPID([]string{"run", "-it", "-v", fmt.Sprintf("%s:/h", udsDir), fedoraMinimal, "bash", "-c", sigCatch})
Expect(ok).To(BeTrue())
uds, _ := os.OpenFile(udsPath, os.O_RDONLY, 0600)
defer uds.Close()
// Wait for the script in the container to alert us that it is READY
counter := 0
for {
buf := make([]byte, 1024)
n, err := uds.Read(buf[:])
if err != nil && err != io.EOF {
fmt.Println(err)
return
}
data := string(buf[0:n])
if strings.Contains(data, "READY") {
break
}
time.Sleep(1 * time.Second)
if counter == 15 {
os.Exit(1)
}
counter++
}
// Ok, container is up and running now and so is the script
// Kill with given signal
if err := unix.Kill(pid, signal); err != nil { if err := unix.Kill(pid, signal); err != nil {
Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err)) Fail(fmt.Sprintf("error killing podman process %d: %v", pid, err))
} }
// Kill with -9 to guarantee the container dies // The sending of the signal above will send FOO to the socket; here we
killSession := podmanTest.Podman([]string{"kill", "-s", "9", "test1"}) // listen to the socket for that.
killSession.WaitWithDefaultTimeout() counter = 0
Expect(killSession.ExitCode()).To(Equal(0)) for {
buf := make([]byte, 1024)
session.WaitWithDefaultTimeout() n, err := uds.Read(buf[:])
Expect(session.ExitCode()).To(Equal(0)) if err != nil {
ok, _ = session.GrepString(fmt.Sprintf("Received %d", signal)) fmt.Println(err)
Expect(ok).To(BeTrue()) return
}
data := string(buf[0:n])
if strings.Contains(data, "FOO") {
break
}
time.Sleep(1 * time.Second)
if counter == 15 {
os.Exit(1)
}
counter++
}
}) })
Specify("signals are not forwarded to container with sig-proxy false", func() { Specify("signals are not forwarded to container with sig-proxy false", func() {
@ -99,4 +137,5 @@ var _ = Describe("Podman run with --sig-proxy", func() {
ok, _ = session.GrepString(fmt.Sprintf("Received %d", signal)) ok, _ = session.GrepString(fmt.Sprintf("Received %d", signal))
Expect(ok).To(BeFalse()) Expect(ok).To(BeFalse())
}) })
}) })