github.com/onsi/ginkgo@v1.16.6-0.20211118180735-4e1925ba4c95/internal/internal_integration/config_flake_attempts_test.go (about) 1 package internal_integration_test 2 3 import ( 4 "fmt" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/ginkgo/internal/test_helpers" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("when config.FlakeAttempts is greater than 1", func() { 12 var success bool 13 JustBeforeEach(func() { 14 var counterA, counterC int 15 16 success, _ = RunFixture("flakey success", func() { 17 It("A", rt.T("A", func() { 18 counterA += 1 19 if counterA < 2 { 20 F(fmt.Sprintf("A - %d", counterA)) 21 } 22 })) 23 It("B", func() {}) 24 It("C", FlakeAttempts(1), rt.T("C", func() { //the config flag overwrites the individual test annotations 25 counterC += 1 26 writer.Write([]byte(fmt.Sprintf("C - attempt #%d\n", counterC))) 27 if counterC < 3 { 28 F(fmt.Sprintf("C - %d", counterC)) 29 } 30 })) 31 }) 32 }) 33 34 Context("when a test succeeds within the correct number of attempts", func() { 35 BeforeEach(func() { 36 conf.FlakeAttempts = 3 37 }) 38 39 It("reports that the suite passed, but with flaked specs", func() { 40 Ω(success).Should(BeTrue()) 41 Ω(reporter.End).Should(BeASuiteSummary(NSpecs(3), NFailed(0), NPassed(3), NFlaked(2))) 42 }) 43 44 It("reports that the test passed with the correct number of attempts", func() { 45 Ω(reporter.Did.Find("A")).Should(HavePassed(NumAttempts(2))) 46 Ω(reporter.Did.Find("B")).Should(HavePassed(NumAttempts(1))) 47 Ω(reporter.Did.Find("C")).Should(HavePassed(NumAttempts(3), 48 CapturedGinkgoWriterOutput("C - attempt #1\n\nGinkgo: Attempt #1 Failed. Retrying...\nC - attempt #2\n\nGinkgo: Attempt #2 Failed. Retrying...\nC - attempt #3\n"))) 49 }) 50 }) 51 52 Context("when the test fails", func() { 53 BeforeEach(func() { 54 conf.FlakeAttempts = 2 55 }) 56 57 It("reports that the suite failed", func() { 58 Ω(success).Should(BeFalse()) 59 Ω(reporter.End).Should(BeASuiteSummary(NSpecs(3), NFailed(1), NPassed(2), NFlaked(1))) 60 }) 61 62 It("reports that the test failed with the correct number of attempts", func() { 63 Ω(reporter.Did.Find("A")).Should(HavePassed(NumAttempts(2))) 64 Ω(reporter.Did.Find("B")).Should(HavePassed(NumAttempts(1))) 65 Ω(reporter.Did.Find("C")).Should(HaveFailed("C - 2", NumAttempts(2), 66 CapturedGinkgoWriterOutput("C - attempt #1\n\nGinkgo: Attempt #1 Failed. Retrying...\nC - attempt #2\n"))) 67 }) 68 }) 69 })