-
Notifications
You must be signed in to change notification settings - Fork 253
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
fix(formatter): On concurrent execution, execute formatter at end of Scenario #645
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b299fa7
fix(formatter): add onflush logger only print output at end of scenar…
tigh-latte 7cb515a
add to changelog
tigh-latte 422971c
fix tests
tigh-latte 5714cbd
fix scenario outline output for the Pretty formatter
tigh-latte 418b770
fix casing for linter
tigh-latte 05e999e
add coverage for new storage function
tigh-latte 76333c7
relate suite back to where it was originally
tigh-latte 4df4dc2
better type assertion on flush log
tigh-latte 7d0db5f
var name for asserted formatter that doesn't clash with stdlib's fmt
tigh-latte 72dccf0
add coverage to summary
tigh-latte bdbcade
only defer flush func when running concurrently
tigh-latte db14449
much more concise way of deferring the flush
tigh-latte b3b7d25
Merge branch 'main' into fix/concurrent-logging
vearutop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package formatters | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/cucumber/godog/formatters" | ||
messages "github.com/cucumber/messages/go/v21" | ||
) | ||
|
||
// WrapOnFlush wrap a `formatters.Formatter` in a `formatters.FlushFormatter`, which only | ||
// executes when `Flush` is called | ||
func WrapOnFlush(fmt formatters.Formatter) formatters.FlushFormatter { | ||
return &onFlushFormatter{ | ||
fmt: fmt, | ||
fns: make([]func(), 0), | ||
mu: &sync.Mutex{}, | ||
} | ||
} | ||
|
||
type onFlushFormatter struct { | ||
fmt formatters.Formatter | ||
fns []func() | ||
mu *sync.Mutex | ||
} | ||
|
||
func (o *onFlushFormatter) Pickle(pickle *messages.Pickle) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Pickle(pickle) | ||
}) | ||
} | ||
|
||
func (o *onFlushFormatter) Passed(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Passed(pickle, step, definition) | ||
}) | ||
} | ||
|
||
// Ambiguous implements formatters.Formatter. | ||
func (o *onFlushFormatter) Ambiguous(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition, err error) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Ambiguous(pickle, step, definition, err) | ||
}) | ||
} | ||
|
||
// Defined implements formatters.Formatter. | ||
func (o *onFlushFormatter) Defined(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Defined(pickle, step, definition) | ||
}) | ||
} | ||
|
||
// Failed implements formatters.Formatter. | ||
func (o *onFlushFormatter) Failed(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition, err error) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Failed(pickle, step, definition, err) | ||
}) | ||
} | ||
|
||
// Feature implements formatters.Formatter. | ||
func (o *onFlushFormatter) Feature(pickle *messages.GherkinDocument, p string, c []byte) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Feature(pickle, p, c) | ||
}) | ||
} | ||
|
||
// Pending implements formatters.Formatter. | ||
func (o *onFlushFormatter) Pending(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Pending(pickle, step, definition) | ||
}) | ||
} | ||
|
||
// Skipped implements formatters.Formatter. | ||
func (o *onFlushFormatter) Skipped(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Skipped(pickle, step, definition) | ||
}) | ||
} | ||
|
||
// Summary implements formatters.Formatter. | ||
func (o *onFlushFormatter) Summary() { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Summary() | ||
}) | ||
} | ||
|
||
// TestRunStarted implements formatters.Formatter. | ||
func (o *onFlushFormatter) TestRunStarted() { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.TestRunStarted() | ||
}) | ||
} | ||
|
||
// Undefined implements formatters.Formatter. | ||
func (o *onFlushFormatter) Undefined(pickle *messages.Pickle, step *messages.PickleStep, definition *formatters.StepDefinition) { | ||
o.fns = append(o.fns, func() { | ||
o.fmt.Undefined(pickle, step, definition) | ||
}) | ||
} | ||
|
||
// Flush the logs. | ||
func (o *onFlushFormatter) Flush() { | ||
o.mu.Lock() | ||
defer o.mu.Unlock() | ||
for _, fn := range o.fns { | ||
fn() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package formatters | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var flushMock = DummyFormatter{} | ||
|
||
func TestFlushWrapOnFormatter(t *testing.T) { | ||
flushMock.tt = t | ||
|
||
fmt := WrapOnFlush(&flushMock) | ||
|
||
fmt.Feature(document, str, byt) | ||
fmt.TestRunStarted() | ||
fmt.Pickle(pickle) | ||
fmt.Defined(pickle, step, definition) | ||
fmt.Passed(pickle, step, definition) | ||
fmt.Skipped(pickle, step, definition) | ||
fmt.Undefined(pickle, step, definition) | ||
fmt.Failed(pickle, step, definition, err) | ||
fmt.Pending(pickle, step, definition) | ||
fmt.Ambiguous(pickle, step, definition, err) | ||
fmt.Summary() | ||
|
||
assert.Equal(t, 0, flushMock.CountFeature) | ||
assert.Equal(t, 0, flushMock.CountTestRunStarted) | ||
assert.Equal(t, 0, flushMock.CountPickle) | ||
assert.Equal(t, 0, flushMock.CountDefined) | ||
assert.Equal(t, 0, flushMock.CountPassed) | ||
assert.Equal(t, 0, flushMock.CountSkipped) | ||
assert.Equal(t, 0, flushMock.CountUndefined) | ||
assert.Equal(t, 0, flushMock.CountFailed) | ||
assert.Equal(t, 0, flushMock.CountPending) | ||
assert.Equal(t, 0, flushMock.CountAmbiguous) | ||
assert.Equal(t, 0, flushMock.CountSummary) | ||
|
||
fmt.Flush() | ||
|
||
assert.Equal(t, 1, flushMock.CountFeature) | ||
assert.Equal(t, 1, flushMock.CountTestRunStarted) | ||
assert.Equal(t, 1, flushMock.CountPickle) | ||
assert.Equal(t, 1, flushMock.CountDefined) | ||
assert.Equal(t, 1, flushMock.CountPassed) | ||
assert.Equal(t, 1, flushMock.CountSkipped) | ||
assert.Equal(t, 1, flushMock.CountUndefined) | ||
assert.Equal(t, 1, flushMock.CountFailed) | ||
assert.Equal(t, 1, flushMock.CountPending) | ||
assert.Equal(t, 1, flushMock.CountAmbiguous) | ||
assert.Equal(t, 1, flushMock.CountSummary) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 only needed to be done for the Pretty formatter, so I wasn't sure if I should just do it after
MustGetPickleStepResultsByPickleID
infmt_pretty.go
, or create a function for it.I've opted to create a function with a pretty bad name, so let me know if yous are happy with this.