interrupt_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package integration_test
  2. import (
  3. "os/exec"
  4. . "github.com/onsi/ginkgo"
  5. . "github.com/onsi/gomega"
  6. "github.com/onsi/gomega/gbytes"
  7. "github.com/onsi/gomega/gexec"
  8. )
  9. var _ = Describe("Interrupt", func() {
  10. var pathToTest string
  11. BeforeEach(func() {
  12. pathToTest = tmpPath("hanging")
  13. copyIn(fixturePath("hanging_suite"), pathToTest, false)
  14. })
  15. Context("when interrupting a suite", func() {
  16. var session *gexec.Session
  17. BeforeEach(func() {
  18. //we need to signal the actual process, so we must compile the test first
  19. var err error
  20. cmd := exec.Command("go", "test", "-c")
  21. cmd.Dir = pathToTest
  22. session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
  23. Ω(err).ShouldNot(HaveOccurred())
  24. Eventually(session).Should(gexec.Exit(0))
  25. //then run the compiled test directly
  26. cmd = exec.Command("./hanging.test", "--test.v=true", "--ginkgo.noColor")
  27. cmd.Dir = pathToTest
  28. session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
  29. Ω(err).ShouldNot(HaveOccurred())
  30. Eventually(session).Should(gbytes.Say("Sleeping..."))
  31. session.Interrupt()
  32. Eventually(session, 1000).Should(gexec.Exit(1))
  33. })
  34. It("should emit the contents of the GinkgoWriter", func() {
  35. Ω(session).Should(gbytes.Say("Just beginning"))
  36. Ω(session).Should(gbytes.Say("Almost there..."))
  37. Ω(session).Should(gbytes.Say("Hanging Out"))
  38. })
  39. It("should run the AfterSuite", func() {
  40. Ω(session).Should(gbytes.Say("Heading Out After Suite"))
  41. })
  42. })
  43. })