Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 1109168

Browse files
committed
Add test for --sig-proxy with a TTY
Add a test to verify that killing the docker CLI forwards the signal to the container. Test-case for moby/moby 28872 Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 7cf1a8d4c96d198e208af2d75d14ab32b8c26dfe) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 79f5dbcd55a7aad3daabaa6f646509025aacf386 Component: cli
1 parent 99e61e2 commit 1109168

30 files changed

Lines changed: 850 additions & 0 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package container
2+
3+
import (
4+
"os/exec"
5+
"strings"
6+
"syscall"
7+
"testing"
8+
"time"
9+
10+
"github.com/docker/cli/e2e/internal/fixtures"
11+
"github.com/kr/pty"
12+
"gotest.tools/assert"
13+
"gotest.tools/icmd"
14+
"gotest.tools/poll"
15+
)
16+
17+
// TestSigProxyWithTTY tests that killing the docker CLI forwards the signal to
18+
// the container, and kills the container's process. Test-case for moby/moby#28872
19+
func TestSigProxyWithTTY(t *testing.T) {
20+
_, tty, err := pty.Open()
21+
assert.NilError(t, err, "could not open pty")
22+
defer func() { _ = tty.Close() }()
23+
24+
containerName := "repro-28872"
25+
cmd := exec.Command("docker", "run", "-i", "-t", "--init", "--name", containerName, fixtures.BusyboxImage, "sleep", "30")
26+
cmd.Stdin = tty
27+
cmd.Stdout = tty
28+
cmd.Stderr = tty
29+
30+
err = cmd.Start()
31+
out, _ := cmd.CombinedOutput()
32+
assert.NilError(t, err, "failed to start container: %s", out)
33+
defer icmd.RunCommand("docker", "container", "rm", "-f", containerName)
34+
35+
poll.WaitOn(t, containerExistsWithStatus(t, containerName, "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
36+
37+
pid := cmd.Process.Pid
38+
t.Logf("terminating PID %d", pid)
39+
err = syscall.Kill(pid, syscall.SIGTERM)
40+
assert.NilError(t, err)
41+
42+
poll.WaitOn(t, containerExistsWithStatus(t, containerName, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
43+
}
44+
45+
func containerExistsWithStatus(t *testing.T, containerID, status string) func(poll.LogT) poll.Result {
46+
return func(poll.LogT) poll.Result {
47+
result := icmd.RunCommand("docker", "inspect", "-f", "{{ .State.Status }}", containerID)
48+
// ignore initial failures as the container may not yet exist (i.e., don't result.Assert(t, icmd.Success))
49+
50+
actual := strings.TrimSpace(result.Stdout())
51+
if actual == status {
52+
return poll.Success()
53+
}
54+
return poll.Continue("expected status %s != %s", status, actual)
55+
}
56+
}

components/cli/vendor.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce8
4646
github.com/jaguilar/vt100 ad4c4a5743050fb7f88ce968dca9422f72a0e3f2 git://github.com/tonistiigi/vt100.git
4747
github.com/json-iterator/go 0ff49de124c6f76f8494e194af75bde0f1a49a29 # 1.1.6
4848
github.com/konsorten/go-windows-terminal-sequences f55edac94c9bbba5d6182a4be46d86a2c9b5b50e # v1.0.2
49+
github.com/kr/pty 521317be5ebc228a0f0ede099fa2a0b5ece22e49 # v1.1.4
4950
github.com/mattn/go-shellwords a72fbe27a1b0ed0df2f02754945044ce1456608b # v1.0.5
5051
github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1
5152
github.com/Microsoft/go-winio 84b4ab48a50763fe7b3abcef38e5205c12027fac

components/cli/vendor/github.com/kr/pty/License

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/README.md

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/doc.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/go.mod

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/ioctl.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/ioctl_bsd.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/cli/vendor/github.com/kr/pty/pty_darwin.go

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)