Skip to content

Commit

Permalink
feat: allow MustPassRepeatedly decorator to be set at suite level (#1266
Browse files Browse the repository at this point in the history
)
  • Loading branch information
maxcleme authored Aug 23, 2023
1 parent d696c7b commit 05de518
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config_override_fixture_test
package config_override_label_filter_fixture_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package config_override_label_filter_fixture_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestConfigOverrideFixture(t *testing.T) {
RegisterFailHandler(Fail)
suiteConfig, reporterConfig := GinkgoConfiguration()
suiteConfig.MustPassRepeatedly = 10
RunSpecs(t, "ConfigOverrideFixture Suite", suiteConfig, reporterConfig)
}

var _ = Describe("tests", func() {
It("suite config overrides decorator", MustPassRepeatedly(2), func() {
Ω(CurrentSpecReport().MaxMustPassRepeatedly).Should(Equal(10))
})
})
4 changes: 2 additions & 2 deletions integration/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ var _ = Describe("Flags Specs", func() {
})

It("should allow configuration overrides", func() {
fm.MountFixture("config_override")
session := startGinkgo(fm.PathTo("config_override"), "--label-filter=NORUN", "--no-color")
fm.MountFixture("config_override_label_filter")
session := startGinkgo(fm.PathTo("config_override_label_filter"), "--label-filter=NORUN", "--no-color")
Eventually(session).Should(gexec.Exit(0), "Succeeds because --label-filter is overridden by the test suite itself.")
output := string(session.Out.Contents())
Ω(output).Should(ContainSubstring("2 Specs"))
Expand Down
11 changes: 11 additions & 0 deletions integration/repeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,15 @@ var _ = Describe("Repeat", func() {
Ω(session.Err).Should(gbytes.Say("--repeat and --until-it-fails are both set"))
})
})

Context("if MustPassRepeatedly is set at suite config level", func() {
BeforeEach(func() {
fm.MountFixture("config_override_must_pass_repeatedly")
})

It("it should override node decorator", func() {
session := startGinkgo(fm.PathTo("config_override_must_pass_repeatedly"))
Eventually(session).Should(gexec.Exit(0))
})
})
})
5 changes: 4 additions & 1 deletion internal/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ func (g *group) run(specs Specs) {
if !skip {
var maxAttempts = 1

if g.suite.currentSpecReport.MaxMustPassRepeatedly > 0 {
if g.suite.config.MustPassRepeatedly > 0 {
maxAttempts = g.suite.config.MustPassRepeatedly
g.suite.currentSpecReport.MaxMustPassRepeatedly = maxAttempts
} else if g.suite.currentSpecReport.MaxMustPassRepeatedly > 0 {
maxAttempts = max(1, spec.MustPassRepeatedly())
} else if g.suite.config.FlakeAttempts > 0 {
maxAttempts = g.suite.config.FlakeAttempts
Expand Down
57 changes: 57 additions & 0 deletions internal/internal_integration/config_must_pass_repeatedly_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package internal_integration_test

import (
"fmt"

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

var _ = Describe("when config.MustPassRepeatedly is greater than 1", func() {
var success bool
JustBeforeEach(func() {
var counterB int
success, _ = RunFixture("flakey success", func() {
It("A", func() {})
It("B", func() {
counterB += 1
if counterB == 8 {
F(fmt.Sprintf("C - %d", counterB))
}
})
})
})

Context("when all tests pass", func() {
BeforeEach(func() {
conf.MustPassRepeatedly = 5
})

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

It("reports that the tests passed with the correct number of attempts", func() {
Ω(reporter.Did.Find("A")).Should(HavePassed(NumAttempts(5)))
Ω(reporter.Did.Find("B")).Should(HavePassed(NumAttempts(5)))
})
})

Context("when a test fails", func() {
BeforeEach(func() {
conf.MustPassRepeatedly = 10
})

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

It("reports that the tests failed with the correct number of attempts", func() {
Ω(reporter.Did.Find("A")).Should(HavePassed(NumAttempts(10)))
Ω(reporter.Did.Find("B")).Should(HaveFailed(NumAttempts(8)))
})
})
})
1 change: 1 addition & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type SuiteConfig struct {
FailOnPending bool
FailFast bool
FlakeAttempts int
MustPassRepeatedly int
DryRun bool
PollProgressAfter time.Duration
PollProgressInterval time.Duration
Expand Down

0 comments on commit 05de518

Please sign in to comment.