@@ -29,17 +29,20 @@ package main
2929
3030import (
3131 "fmt"
32+ "io/ioutil"
33+ "log"
3234 "os"
3335 "os/exec"
3436 "path/filepath"
37+ "strings"
3538 "testing"
3639 "time"
3740
38- "gotest.tools/golden"
39-
4041 . "github.com/onsi/gomega"
4142 "github.com/stretchr/testify/suite"
4243
44+ "gotest.tools/golden"
45+
4346 . "github.com/docker/api/tests/framework"
4447)
4548
@@ -79,6 +82,37 @@ func (s *E2eSuite) TestSetupError() {
7982 })
8083}
8184
85+ func (s * E2eSuite ) TestKillChildOnCancel () {
86+ It ("should kill docker-classic if parent command is cancelled" , func () {
87+ out := s .NewCommand ("ps" , "-x" ).ExecOrDie ()
88+ Expect (out ).NotTo (ContainSubstring ("docker-classic" ))
89+
90+ dir := s .ConfigDir
91+ Expect (ioutil .WriteFile (filepath .Join (dir , "Dockerfile" ), []byte (`FROM alpine:3.10
92+ RUN sleep 100` ), 0644 )).To (Succeed ())
93+ shutdown := make (chan time.Time )
94+ errs := make (chan error )
95+ ctx := s .NewDockerCommand ("build" , "--no-cache" , "-t" , "test-sleep-image" , "." ).WithinDirectory (dir ).WithTimeout (shutdown )
96+ go func () {
97+ _ , err := ctx .Exec ()
98+ errs <- err
99+ }()
100+ err := WaitFor (time .Second , 3 * time .Second , errs , func () bool {
101+ out := s .NewCommand ("ps" , "-x" ).ExecOrDie ()
102+ return strings .Contains (out , "docker-classic" )
103+ })
104+ Expect (err ).NotTo (HaveOccurred ())
105+ log .Println ("Killing docker process" )
106+
107+ close (shutdown )
108+ err = WaitFor (time .Second , 4 * time .Second , nil , func () bool {
109+ out := s .NewCommand ("ps" , "-x" ).ExecOrDie ()
110+ return ! strings .Contains (out , "docker-classic" )
111+ })
112+ Expect (err ).NotTo (HaveOccurred ())
113+ })
114+ }
115+
82116func (s * E2eSuite ) TestLegacy () {
83117 It ("should list all legacy commands" , func () {
84118 output := s .NewDockerCommand ("--help" ).ExecOrDie ()
0 commit comments