skip_win_ci_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. Copyright 2020 Docker, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package main
  14. import (
  15. "io/ioutil"
  16. "log"
  17. "path/filepath"
  18. "strings"
  19. "testing"
  20. "time"
  21. . "github.com/onsi/gomega"
  22. "github.com/stretchr/testify/suite"
  23. . "github.com/docker/api/tests/framework"
  24. )
  25. type NonWinCIE2eSuite struct {
  26. Suite
  27. }
  28. func (s *NonWinCIE2eSuite) TestKillChildOnCancel() {
  29. It("should kill com.docker.cli if parent command is cancelled", func() {
  30. imageName := "test-sleep-image"
  31. out := s.ListProcessesCommand().ExecOrDie()
  32. Expect(out).NotTo(ContainSubstring(imageName))
  33. dir := s.ConfigDir
  34. Expect(ioutil.WriteFile(filepath.Join(dir, "Dockerfile"), []byte(`FROM alpine:3.10
  35. RUN sleep 100`), 0644)).To(Succeed())
  36. shutdown := make(chan time.Time)
  37. errs := make(chan error)
  38. ctx := s.NewDockerCommand("build", "--no-cache", "-t", imageName, ".").WithinDirectory(dir).WithTimeout(shutdown)
  39. go func() {
  40. _, err := ctx.Exec()
  41. errs <- err
  42. }()
  43. err := WaitFor(time.Second, 10*time.Second, errs, func() bool {
  44. out := s.ListProcessesCommand().ExecOrDie()
  45. return strings.Contains(out, imageName)
  46. })
  47. Expect(err).NotTo(HaveOccurred())
  48. log.Println("Killing docker process")
  49. close(shutdown)
  50. err = WaitFor(time.Second, 12*time.Second, nil, func() bool {
  51. out := s.ListProcessesCommand().ExecOrDie()
  52. return !strings.Contains(out, imageName)
  53. })
  54. Expect(err).NotTo(HaveOccurred())
  55. })
  56. }
  57. func TestNonWinCIE2(t *testing.T) {
  58. suite.Run(t, new(NonWinCIE2eSuite))
  59. }