New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduction of 'MustPassRepeatedly' decorator #1051
Changes from 3 commits
053369f
d83abd9
f8d214e
5356dc4
d9b6aec
ee9b1cf
705d8c4
6abd43e
c729308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package decorations_fixture_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestDecorationsFixture(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "DecorationsFixture Suite") | ||
} | ||
|
||
var countFlake = 0 | ||
var countRepeat = 0 | ||
|
||
var _ = Describe("some decorated tests", func() { | ||
It("passes eventually", func() { | ||
countFlake += 1 | ||
if countFlake < 3 { | ||
Fail("fail") | ||
} | ||
}, FlakeAttempts(3)) | ||
|
||
// how to/should we test negative test cases? | ||
It("fails eventually", func() { | ||
countRepeat += 1 | ||
if countRepeat >= 3 { | ||
Fail(fmt.Sprintf("failed on attempt #%d", countRepeat)) | ||
} | ||
}, MustPassRepeatedly(3)) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package invalid_decorations_flakeattempts_mustpassrepeatedly_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestInvalidDecorations(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "InvalidDecorations Suite - MustPassRepeatedly and FlakeAttempts") | ||
} | ||
|
||
var _ = Describe("invalid decorators: mustpassrepeatedly and flakeattempts", FlakeAttempts(3), MustPassRepeatedly(3), func() { | ||
It("never runs", func() { | ||
|
||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package invalid_decorations_focused_pending_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestInvalidDecorations(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "InvalidDecorations Suite - Focused and Pending") | ||
} | ||
|
||
var _ = Describe("invalid decorators: focused and pending", Focus, Pending, func() { | ||
It("never runs", func() { | ||
|
||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package internal | |
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"time" | ||
|
||
"github.com/onsi/ginkgo/v2/types" | ||
|
@@ -118,6 +119,8 @@ func (g *group) initialReportForSpec(spec Spec) types.SpecReport { | |
ParallelProcess: g.suite.config.ParallelProcess, | ||
IsSerial: spec.Nodes.HasNodeMarkedSerial(), | ||
IsInOrderedContainer: !spec.Nodes.FirstNodeMarkedOrdered().IsZero(), | ||
MaxFlakeAttempts: spec.Nodes.GetMaxFlakeAttempts(), | ||
MaxMustPassRepeatedly: spec.Nodes.GetMaxMustPassRepeatedly(), | ||
} | ||
} | ||
|
||
|
@@ -299,16 +302,37 @@ func (g *group) run(specs Specs) { | |
|
||
g.suite.currentSpecReport.StartTime = time.Now() | ||
if !skip { | ||
maxAttempts := max(1, spec.FlakeAttempts()) | ||
|
||
var maxAttempts = 1 | ||
var multipleExecutionDecorator interface{} | ||
|
||
if g.suite.currentSpecReport.MaxFlakeAttempts > 0 { | ||
multipleExecutionDecorator = reflect.TypeOf(FlakeAttempts(0)) | ||
maxAttempts = max(1, spec.FlakeAttempts()) | ||
} | ||
if g.suite.config.FlakeAttempts > 0 { | ||
multipleExecutionDecorator = reflect.TypeOf(FlakeAttempts(0)) | ||
maxAttempts = g.suite.config.FlakeAttempts | ||
g.suite.currentSpecReport.MaxFlakeAttempts = maxAttempts | ||
} | ||
|
||
if g.suite.currentSpecReport.MaxMustPassRepeatedly > 0 { | ||
multipleExecutionDecorator = reflect.TypeOf(MustPassRepeatedly(0)) | ||
maxAttempts = max(1, spec.MustPassRepeatedly()) | ||
} | ||
|
||
maxAttemptForLoop: | ||
for attempt := 0; attempt < maxAttempts; attempt++ { | ||
g.suite.currentSpecReport.NumAttempts = attempt + 1 | ||
g.suite.writer.Truncate() | ||
g.suite.outputInterceptor.StartInterceptingOutput() | ||
if attempt > 0 { | ||
fmt.Fprintf(g.suite.writer, "\nGinkgo: Attempt #%d Failed. Retrying...\n", attempt) | ||
switch t := multipleExecutionDecorator; { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than tracking |
||
case t == reflect.TypeOf(FlakeAttempts(0)): | ||
fmt.Fprintf(g.suite.writer, "\nGinkgo: Attempt #%d Failed. Retrying...\n", attempt) | ||
case t == reflect.TypeOf(MustPassRepeatedly(0)): | ||
fmt.Fprintf(g.suite.writer, "\nGinkgo: Attempt #%d Passed. Repeating...\n", attempt) | ||
} | ||
} | ||
|
||
g.attemptSpec(attempt == maxAttempts-1, spec) | ||
|
@@ -318,9 +342,17 @@ func (g *group) run(specs Specs) { | |
g.suite.currentSpecReport.CapturedGinkgoWriterOutput += string(g.suite.writer.Bytes()) | ||
g.suite.currentSpecReport.CapturedStdOutErr += g.suite.outputInterceptor.StopInterceptingAndReturnOutput() | ||
|
||
if g.suite.currentSpecReport.State.Is(types.SpecStatePassed | types.SpecStateSkipped | types.SpecStateAborted | types.SpecStateInterrupted) { | ||
break | ||
switch t := multipleExecutionDecorator; { | ||
case t == reflect.TypeOf(FlakeAttempts(0)): | ||
if g.suite.currentSpecReport.State.Is(types.SpecStatePassed | types.SpecStateSkipped | types.SpecStateAborted | types.SpecStateInterrupted) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks right to me. |
||
break maxAttemptForLoop | ||
} | ||
case t == reflect.TypeOf(MustPassRepeatedly(0)): | ||
if g.suite.currentSpecReport.State.Is(types.SpecStateFailureStates | types.SpecStateSkipped) { | ||
break maxAttemptForLoop | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a nitpick (sorry!) but I've been trying to call "tests" in Ginkgo "specs" throughout the documentation (though I'm sure I've missed quite a few!). Would you be up for changing the language here from test/tests to spec/specs?
The rationale is to distinguish Ginkgo specs from regular go tests - but it's mostly about consistency tbh.