-
-
Notifications
You must be signed in to change notification settings - Fork 657
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 1 commit
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)) | ||
}) |
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() { | ||
|
||
}) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,8 +119,8 @@ func (g *group) initialReportForSpec(spec Spec) types.SpecReport { | |
ParallelProcess: g.suite.config.ParallelProcess, | ||
IsSerial: spec.Nodes.HasNodeMarkedSerial(), | ||
IsInOrderedContainer: !spec.Nodes.FirstNodeMarkedOrdered().IsZero(), | ||
IsFlakeAttempts: spec.Nodes.HasSetFlakeAttempts(), | ||
IsRepeatAttempts: spec.Nodes.HasSetRepeatAttempts(), | ||
MaxFlakeAttempts: spec.Nodes.GetMaxFlakeAttempts(), | ||
MaxMustPassRepeatedly: spec.Nodes.GetMaxMustPassRepeatedly(), | ||
} | ||
} | ||
|
||
|
@@ -306,21 +306,19 @@ func (g *group) run(specs Specs) { | |
var maxAttempts = 1 | ||
var multipleExecutionDecorator interface{} | ||
|
||
if g.suite.currentSpecReport.IsFlakeAttempts { | ||
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.IsFlakeAttempts = true | ||
g.suite.currentSpecReport.MaxFlakeAttempts = maxAttempts | ||
} | ||
|
||
if g.suite.currentSpecReport.IsRepeatAttempts { | ||
multipleExecutionDecorator = reflect.TypeOf(RepeatAttempts(0)) | ||
maxAttempts = max(1, spec.RepeatAttempts()) | ||
} else if g.suite.config.FlakeAttempts > 0 { | ||
//What should be the behavior when --flakeattempts is defined in CLI and the RepeatAttemps decorator is used? | ||
if g.suite.currentSpecReport.MaxMustPassRepeatedly > 0 { | ||
multipleExecutionDecorator = reflect.TypeOf(MustPassRepeatedly(0)) | ||
maxAttempts = max(1, spec.MustPassRepeatedly()) | ||
} | ||
|
||
maxAttemptForLoop: | ||
|
@@ -332,8 +330,8 @@ func (g *group) run(specs Specs) { | |
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(RepeatAttempts(0)): | ||
fmt.Fprintf(g.suite.writer, "\nGinkgo: Attempt #%d Passed. Retrying...\n", attempt) | ||
case t == reflect.TypeOf(MustPassRepeatedly(0)): | ||
fmt.Fprintf(g.suite.writer, "\nGinkgo: Attempt #%d Passed. Repeating...\n", attempt) | ||
} | ||
} | ||
|
||
|
@@ -349,8 +347,8 @@ func (g *group) run(specs Specs) { | |
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(RepeatAttempts(0)): | ||
if g.suite.currentSpecReport.State.Is(types.SpecStateFailed | types.SpecStateSkipped | types.SpecStateAborted | types.SpecStateInterrupted) { | ||
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.