File: config_flake_attempts_test.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (95 lines) | stat: -rw-r--r-- 3,296 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package internal_integration_test

import (
	"fmt"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/ginkgo/v2/internal/test_helpers"
	"github.com/onsi/ginkgo/v2/types"
	. "github.com/onsi/gomega"
)

var _ = Describe("when config.FlakeAttempts is greater than 1", func() {
	var success bool
	JustBeforeEach(func() {
		var counterA, counterC int

		success, _ = RunFixture("flakey success", func() {
			It("A", rt.T("A", func() {
				counterA += 1
				if counterA < 2 {
					F(fmt.Sprintf("A - %d", counterA))
				}
			}))
			It("B", func() {})
			It("C", FlakeAttempts(1), rt.T("C", func() { //the config flag overwrites the individual test annotations
				counterC += 1
				By(fmt.Sprintf("C - attempt #%d", counterC))
				if counterC < 3 {
					F(fmt.Sprintf("C - %d", counterC))
				}
			}))
		})
	})

	Context("when a test succeeds within the correct number of attempts", func() {
		BeforeEach(func() {
			conf.FlakeAttempts = 3
		})

		It("reports that the suite passed, but with flaked specs", func() {
			Ω(success).Should(BeTrue())
			Ω(reporter.End).Should(BeASuiteSummary(NSpecs(3), NFailed(0), NPassed(3), NFlaked(2)))
		})

		It("reports that the test passed with the correct number of attempts", func() {
			Ω(reporter.Did.Find("A")).Should(HavePassed(NumAttempts(2)))
			Ω(reporter.Did.Find("B")).Should(HavePassed(NumAttempts(1)))
			Ω(reporter.Did.Find("C")).Should(HavePassed(NumAttempts(3)))
			Ω(reporter.Did.Find("C").Timeline()).Should(BeTimelineContaining(
				BeSpecEvent(types.SpecEventByStart, "C - attempt #1"),
				HaveFailed("C - 1"),
				BeSpecEvent(types.SpecEventSpecRetry, 1),
				BeSpecEvent(types.SpecEventByStart, "C - attempt #2"),
				HaveFailed("C - 2"),
				BeSpecEvent(types.SpecEventSpecRetry, 2),
				BeSpecEvent(types.SpecEventByStart, "C - attempt #3"),
			))
		})

		It("includes the intermediate failures as AdditionalFailures (this allows timeline reconstruction)", func() {
			Ω(reporter.Did.Find("C").AdditionalFailures).Should(HaveLen(2))
			Ω(reporter.Did.Find("C").AdditionalFailures[0]).Should(HaveFailed("C - 1"))
			Ω(reporter.Did.Find("C").AdditionalFailures[1]).Should(HaveFailed("C - 2"))
		})
	})

	Context("when the test fails", func() {
		BeforeEach(func() {
			conf.FlakeAttempts = 2
		})

		It("reports that the suite failed", func() {
			Ω(success).Should(BeFalse())
			Ω(reporter.End).Should(BeASuiteSummary(NSpecs(3), NFailed(1), NPassed(2), NFlaked(1)))
		})

		It("reports that the test failed with the correct number of attempts", func() {
			Ω(reporter.Did.Find("A")).Should(HavePassed(NumAttempts(2)))
			Ω(reporter.Did.Find("B")).Should(HavePassed(NumAttempts(1)))
			Ω(reporter.Did.Find("C")).Should(HaveFailed("C - 2", NumAttempts(2)))
			Ω(reporter.Did.Find("C").Timeline()).Should(BeTimelineContaining(
				BeSpecEvent(types.SpecEventByStart, "C - attempt #1"),
				HaveFailed("C - 1"),
				BeSpecEvent(types.SpecEventSpecRetry, 1),
				BeSpecEvent(types.SpecEventByStart, "C - attempt #2"),
			))
		})

		It("includes the intermediate failures as AdditionalFailure, but not the final failure (this allows timeline reconstruction)", func() {
			Ω(reporter.Did.Find("C").AdditionalFailures).Should(HaveLen(1))
			Ω(reporter.Did.Find("C").AdditionalFailures[0]).Should(HaveFailed("C - 1"))
		})

	})
})