Fix flaky test (subject to running tests in //)

This commit is contained in:
Guillaume Tardif 2020-06-11 15:01:43 +02:00
parent 3ad1e699a2
commit 9d4eed2356
2 changed files with 7 additions and 6 deletions

View File

@ -132,7 +132,7 @@ func (s *Suite) ListProcessesCommand() *CmdContext {
if IsWindows() { if IsWindows() {
return s.NewCommand("tasklist") return s.NewCommand("tasklist")
} }
return s.NewCommand("ps") return s.NewCommand("ps", "-x")
} }
// NewCommand creates a command context. // NewCommand creates a command context.

View File

@ -50,22 +50,23 @@ type NonWinCIE2eSuite struct {
func (s *NonWinCIE2eSuite) TestKillChildOnCancel() { func (s *NonWinCIE2eSuite) TestKillChildOnCancel() {
It("should kill docker-classic if parent command is cancelled", func() { It("should kill docker-classic if parent command is cancelled", func() {
imageName := "test-sleep-image"
out := s.ListProcessesCommand().ExecOrDie() out := s.ListProcessesCommand().ExecOrDie()
Expect(out).NotTo(ContainSubstring("docker-classic")) Expect(out).NotTo(ContainSubstring(imageName))
dir := s.ConfigDir dir := s.ConfigDir
Expect(ioutil.WriteFile(filepath.Join(dir, "Dockerfile"), []byte(`FROM alpine:3.10 Expect(ioutil.WriteFile(filepath.Join(dir, "Dockerfile"), []byte(`FROM alpine:3.10
RUN sleep 100`), 0644)).To(Succeed()) RUN sleep 100`), 0644)).To(Succeed())
shutdown := make(chan time.Time) shutdown := make(chan time.Time)
errs := make(chan error) errs := make(chan error)
ctx := s.NewDockerCommand("build", "--no-cache", "-t", "test-sleep-image", ".").WithinDirectory(dir).WithTimeout(shutdown) ctx := s.NewDockerCommand("build", "--no-cache", "-t", imageName, ".").WithinDirectory(dir).WithTimeout(shutdown)
go func() { go func() {
_, err := ctx.Exec() _, err := ctx.Exec()
errs <- err errs <- err
}() }()
err := WaitFor(time.Second, 10*time.Second, errs, func() bool { err := WaitFor(time.Second, 10*time.Second, errs, func() bool {
out := s.ListProcessesCommand().ExecOrDie() out := s.ListProcessesCommand().ExecOrDie()
return strings.Contains(out, "docker-classic") return strings.Contains(out, imageName)
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
log.Println("Killing docker process") log.Println("Killing docker process")
@ -73,7 +74,7 @@ RUN sleep 100`), 0644)).To(Succeed())
close(shutdown) close(shutdown)
err = WaitFor(time.Second, 12*time.Second, nil, func() bool { err = WaitFor(time.Second, 12*time.Second, nil, func() bool {
out := s.ListProcessesCommand().ExecOrDie() out := s.ListProcessesCommand().ExecOrDie()
return !strings.Contains(out, "docker-classic") return !strings.Contains(out, imageName)
}) })
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
@ -108,7 +109,7 @@ func (s *NonWinCIE2eSuite) getGrpcServerAndCLientAddress() (string, string) {
return socketName, socketName return socketName, socketName
} }
func TestE2e(t *testing.T) { func TestNonWinCIE2(t *testing.T) {
suite.Run(t, new(NonWinCIE2eSuite)) suite.Run(t, new(NonWinCIE2eSuite))
} }