Skip to content

Commit 05de518

Browse files
authoredAug 23, 2023
feat: allow MustPassRepeatedly decorator to be set at suite level (#1266)
1 parent d696c7b commit 05de518

File tree

7 files changed

+97
-4
lines changed

7 files changed

+97
-4
lines changed
 

‎integration/_fixtures/config_override_fixture/config_override_fixture_suite_test.go ‎integration/_fixtures/config_override_label_filter_fixture/config_override_fixture_suite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package config_override_fixture_test
1+
package config_override_label_filter_fixture_test
22

33
import (
44
"testing"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package config_override_label_filter_fixture_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestConfigOverrideFixture(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
suiteConfig, reporterConfig := GinkgoConfiguration()
13+
suiteConfig.MustPassRepeatedly = 10
14+
RunSpecs(t, "ConfigOverrideFixture Suite", suiteConfig, reporterConfig)
15+
}
16+
17+
var _ = Describe("tests", func() {
18+
It("suite config overrides decorator", MustPassRepeatedly(2), func() {
19+
Ω(CurrentSpecReport().MaxMustPassRepeatedly).Should(Equal(10))
20+
})
21+
})

‎integration/flags_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ var _ = Describe("Flags Specs", func() {
135135
})
136136

137137
It("should allow configuration overrides", func() {
138-
fm.MountFixture("config_override")
139-
session := startGinkgo(fm.PathTo("config_override"), "--label-filter=NORUN", "--no-color")
138+
fm.MountFixture("config_override_label_filter")
139+
session := startGinkgo(fm.PathTo("config_override_label_filter"), "--label-filter=NORUN", "--no-color")
140140
Eventually(session).Should(gexec.Exit(0), "Succeeds because --label-filter is overridden by the test suite itself.")
141141
output := string(session.Out.Contents())
142142
Ω(output).Should(ContainSubstring("2 Specs"))

‎integration/repeat_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,15 @@ var _ = Describe("Repeat", func() {
9898
Ω(session.Err).Should(gbytes.Say("--repeat and --until-it-fails are both set"))
9999
})
100100
})
101+
102+
Context("if MustPassRepeatedly is set at suite config level", func() {
103+
BeforeEach(func() {
104+
fm.MountFixture("config_override_must_pass_repeatedly")
105+
})
106+
107+
It("it should override node decorator", func() {
108+
session := startGinkgo(fm.PathTo("config_override_must_pass_repeatedly"))
109+
Eventually(session).Should(gexec.Exit(0))
110+
})
111+
})
101112
})

‎internal/group.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,10 @@ func (g *group) run(specs Specs) {
321321
if !skip {
322322
var maxAttempts = 1
323323

324-
if g.suite.currentSpecReport.MaxMustPassRepeatedly > 0 {
324+
if g.suite.config.MustPassRepeatedly > 0 {
325+
maxAttempts = g.suite.config.MustPassRepeatedly
326+
g.suite.currentSpecReport.MaxMustPassRepeatedly = maxAttempts
327+
} else if g.suite.currentSpecReport.MaxMustPassRepeatedly > 0 {
325328
maxAttempts = max(1, spec.MustPassRepeatedly())
326329
} else if g.suite.config.FlakeAttempts > 0 {
327330
maxAttempts = g.suite.config.FlakeAttempts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package internal_integration_test
2+
3+
import (
4+
"fmt"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/ginkgo/v2/internal/test_helpers"
8+
. "github.com/onsi/gomega"
9+
)
10+
11+
var _ = Describe("when config.MustPassRepeatedly is greater than 1", func() {
12+
var success bool
13+
JustBeforeEach(func() {
14+
var counterB int
15+
success, _ = RunFixture("flakey success", func() {
16+
It("A", func() {})
17+
It("B", func() {
18+
counterB += 1
19+
if counterB == 8 {
20+
F(fmt.Sprintf("C - %d", counterB))
21+
}
22+
})
23+
})
24+
})
25+
26+
Context("when all tests pass", func() {
27+
BeforeEach(func() {
28+
conf.MustPassRepeatedly = 5
29+
})
30+
31+
It("reports that the suite passed", func() {
32+
Ω(success).Should(BeTrue())
33+
Ω(reporter.End).Should(BeASuiteSummary(NSpecs(2), NFailed(0), NPassed(2)))
34+
})
35+
36+
It("reports that the tests passed with the correct number of attempts", func() {
37+
Ω(reporter.Did.Find("A")).Should(HavePassed(NumAttempts(5)))
38+
Ω(reporter.Did.Find("B")).Should(HavePassed(NumAttempts(5)))
39+
})
40+
})
41+
42+
Context("when a test fails", func() {
43+
BeforeEach(func() {
44+
conf.MustPassRepeatedly = 10
45+
})
46+
47+
It("reports that the suite failed", func() {
48+
Ω(success).Should(BeFalse())
49+
Ω(reporter.End).Should(BeASuiteSummary(NSpecs(2), NFailed(1), NPassed(1)))
50+
})
51+
52+
It("reports that the tests failed with the correct number of attempts", func() {
53+
Ω(reporter.Did.Find("A")).Should(HavePassed(NumAttempts(10)))
54+
Ω(reporter.Did.Find("B")).Should(HaveFailed(NumAttempts(8)))
55+
})
56+
})
57+
})

‎types/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type SuiteConfig struct {
2727
FailOnPending bool
2828
FailFast bool
2929
FlakeAttempts int
30+
MustPassRepeatedly int
3031
DryRun bool
3132
PollProgressAfter time.Duration
3233
PollProgressInterval time.Duration

0 commit comments

Comments
 (0)
Please sign in to comment.