github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/interrupt_handler/interrupt_handler_test.go (about) 1 package interrupt_handler_test 2 3 import ( 4 "time" 5 6 . "github.com/onsi/ginkgo" 7 "github.com/onsi/ginkgo/internal/interrupt_handler" 8 "github.com/onsi/ginkgo/internal/parallel_support" 9 . "github.com/onsi/ginkgo/internal/test_helpers" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("InterruptHandler", func() { 14 var interruptHandler *interrupt_handler.InterruptHandler 15 Describe("Timeout interrupts", func() { 16 BeforeEach(func() { 17 interruptHandler = interrupt_handler.NewInterruptHandler(500*time.Millisecond, nil) 18 DeferCleanup(interruptHandler.Stop) 19 }) 20 21 It("eventually closes the interrupt channel to signal an interrupt has occurred", func() { 22 status := interruptHandler.Status() 23 Ω(status.Interrupted).Should(BeFalse()) 24 Eventually(status.Channel).Should(BeClosed()) 25 26 Ω(interruptHandler.Status().Interrupted).Should(BeTrue()) 27 }) 28 29 It("notes the cause as 'Interrupted By Timeout'", func() { 30 status := interruptHandler.Status() 31 Eventually(status.Channel).Should(BeClosed()) 32 cause := interruptHandler.Status().Cause 33 Ω(cause).Should(Equal(interrupt_handler.InterruptCauseTimeout)) 34 Ω(interruptHandler.InterruptMessageWithStackTraces()).Should(HavePrefix("Interrupted by Timeout\n\n")) 35 Ω(interruptHandler.InterruptMessageWithStackTraces()).Should(ContainSubstring("Here's a stack trace")) 36 }) 37 38 It("repeatedly triggers an interrupt every 1/10th of the registered timeout", func() { 39 status := interruptHandler.Status() 40 Ω(status.Interrupted).Should(BeFalse()) 41 Eventually(status.Channel).Should(BeClosed()) 42 43 status = interruptHandler.Status() 44 Ω(status.Channel).ShouldNot(BeClosed()) 45 Eventually(status.Channel).Should(BeClosed()) 46 }) 47 }) 48 49 Describe("Interrupting when another Ginkgo process has aborted", func() { 50 var client parallel_support.Client 51 BeforeEach(func() { 52 _, client, _ = SetUpServerAndClient(2) 53 interruptHandler = interrupt_handler.NewInterruptHandler(0, client) 54 DeferCleanup(interruptHandler.Stop) 55 }) 56 57 It("interrupts when the server is told to abort", func() { 58 status := interruptHandler.Status() 59 Consistently(status.Channel).ShouldNot(BeClosed()) 60 client.PostAbort() 61 Eventually(status.Channel).Should(BeClosed()) 62 }) 63 64 It("notes the correct cause and returns an interrupt message that does not include the stacktrace ", func() { 65 status := interruptHandler.Status() 66 client.PostAbort() 67 Eventually(status.Channel).Should(BeClosed()) 68 status = interruptHandler.Status() 69 Ω(status.Cause).Should(Equal(interrupt_handler.InterruptCauseAbortByOtherProcess)) 70 Ω(interruptHandler.InterruptMessageWithStackTraces()).Should(HavePrefix("Interrupted by Other Ginkgo Process")) 71 Ω(interruptHandler.InterruptMessageWithStackTraces()).ShouldNot(ContainSubstring("Here's a stack trace")) 72 }) 73 }) 74 })