Skip to content
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

Fixed Summary Generated Events #3730

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
if !testRunState.RuntimeOptions.NoSummary.Bool {
defer func() {
logger.Debug("Generating the end-of-test summary...")
summaryResult, hsErr := test.initRunner.HandleSummary(globalCtx, &lib.Summary{
summary := &lib.Summary{
Metrics: metricsEngine.ObservedMetrics,
RootGroup: testRunState.GroupSummary.Group(),
TestRunDuration: executionState.GetCurrentTestRunDuration(),
Expand All @@ -201,9 +201,15 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
IsStdOutTTY: c.gs.Stdout.IsTTY,
IsStdErrTTY: c.gs.Stderr.IsTTY,
},
})
}
summaryResult, hsErr := test.initRunner.HandleSummary(globalCtx, summary)
if hsErr == nil {
hsErr = handleSummaryResult(c.gs.FS, c.gs.Stdout, c.gs.Stderr, summaryResult)
waitForSummaryGeneratedEvent := emitEvent(&event.Event{
Type: event.TestSummaryGenerated,
Data: summary,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be better to copy ObservedMetrics and RootGroup instead of directly passing them. They are pointers and they might generate data races if there is a read/write across extensions and/or from k6core.

})
waitForSummaryGeneratedEvent()
}
if hsErr != nil {
logger.WithError(hsErr).Error("failed to handle the end-of-test summary")
Expand Down
3 changes: 3 additions & 0 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,7 @@ func TestEventSystemOK(t *testing.T) {
`got event IterStart with data '{Iteration:4 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event IterEnd with data '{Iteration:4 VUID:1 ScenarioName:default Error:<nil>}'`,
`got event TestEnd with data '<nil>'`,
`got event TestSummaryGenerated with data '&{Summary:map[...]...}'`,
`got event Exit with data '&{Error:<nil>}'`,
}
log := ts.LoggerHook.Lines()
Expand Down Expand Up @@ -2107,6 +2108,7 @@ func TestEventSystemError(t *testing.T) {
"got event IterStart with data '{Iteration:0 VUID:1 ScenarioName:default Error:<nil>}'",
"got event IterEnd with data '{Iteration:0 VUID:1 ScenarioName:default Error:test aborted: oops! at file:///-:11:16(6)}'",
"got event TestEnd with data '<nil>'",
"got event TestSummaryGenerated with data '&{Summary:map[...]...}'",
"got event Exit with data '&{Error:test aborted: oops! at file:///-:11:16(6)}'",
"test aborted: oops! at file:///-:11:16(6)",
},
Expand Down Expand Up @@ -2143,6 +2145,7 @@ func TestEventSystemError(t *testing.T) {
"got event IterEnd with data '{Iteration:1 VUID:1 ScenarioName:default Error:Error: oops!\n\tat file:///-:9:11(3)\n}'",
"Error: oops!\n\tat file:///-:9:11(3)\n",
"got event TestEnd with data '<nil>'",
"got event TestSummaryGenerated with data '&{Summary:map[...]...}'",
"got event Exit with data '&{Error:<nil>}'",
},
expExitCode: 0,
Expand Down
4 changes: 3 additions & 1 deletion event/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ const (
IterEnd
// Exit is emitted when the k6 process is about to exit.
Exit
// TestSummaryGenerated is emitted when the summary is generated.
TestSummaryGenerated
)

//nolint:gochecknoglobals
var (
// GlobalEvents are emitted once per test run.
GlobalEvents = []Type{Init, TestStart, TestEnd, Exit}
GlobalEvents = []Type{Init, TestStart, TestEnd, TestSummaryGenerated, Exit}
// VUEvents are emitted multiple times per each VU.
VUEvents = []Type{IterStart, IterEnd}
)
Expand Down
7 changes: 4 additions & 3 deletions event/type_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ type Summary struct {
NoColor bool // TODO: drop this when noColor is part of the (runtime) options
UIState UIState
}

// String Overiding for tests
func (s *Summary) String() string {
return "&{Summary:map[...]...}"
}
Comment on lines +104 to +106
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess when we agree on the generation part then we should update this with some additional information. We might have Summary{Metrics: number, RootGroup: name/(or nil), and the other fields}.

Loading