From e0e6664d168161e06321b8fd1677dbee8717606d Mon Sep 17 00:00:00 2001 From: Oleg Bespalov Date: Wed, 22 Feb 2023 12:49:11 +0100 Subject: [PATCH 1/4] Fix panic in `k6/execution` Fixing the panic that could happen if try to access the `exec.vu.iterationInScenario` in `setup`. At that moment, the details are not initialized. (cherry picked from commit 26ec301698325983b5f947e16405f0958cd75bc9) --- js/modules/k6/execution/execution.go | 5 ++++ js/modules/k6/execution/execution_test.go | 28 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/js/modules/k6/execution/execution.go b/js/modules/k6/execution/execution.go index 768fbd23569e..a85fa0e1e7f0 100644 --- a/js/modules/k6/execution/execution.go +++ b/js/modules/k6/execution/execution.go @@ -203,6 +203,11 @@ func (mi *ModuleInstance) newVUInfo() (*goja.Object, error) { "idInTest": func() interface{} { return vuState.VUIDGlobal }, "iterationInInstance": func() interface{} { return vuState.Iteration }, "iterationInScenario": func() interface{} { + if vuState.GetScenarioVUIter == nil { + // hasn't been set yet, no iteration stats available + return 0 + } + return vuState.GetScenarioVUIter() }, } diff --git a/js/modules/k6/execution/execution_test.go b/js/modules/k6/execution/execution_test.go index 04b6ee253783..c5cba14f0d54 100644 --- a/js/modules/k6/execution/execution_test.go +++ b/js/modules/k6/execution/execution_test.go @@ -406,6 +406,34 @@ func TestScenarioNoAvailableInInitContext(t *testing.T) { } } +func TestVUDefaultDetails(t *testing.T) { + t.Parallel() + + rt := goja.New() + m, ok := New().NewModuleInstance( + &modulestest.VU{ + RuntimeField: rt, + CtxField: context.Background(), + StateField: &lib.State{ + Options: lib.Options{ + Paused: null.BoolFrom(true), + }, + }, + }, + ).(*ModuleInstance) + require.True(t, ok) + require.NoError(t, rt.Set("exec", m.Exports().Default)) + + props := []string{"idInInstance", "idInTest", "iterationInInstance", "iterationInScenario"} + + for _, code := range props { + prop := fmt.Sprintf("exec.vu.%s", code) + res, err := rt.RunString(prop) + require.NoError(t, err) + require.Equal(t, "0", res.String()) + } +} + func TestTagsDynamicObjectGet(t *testing.T) { t.Parallel() rt := goja.New() From eddb5a68f0c753ae7b8f3d5d0fcb2ad920a66896 Mon Sep 17 00:00:00 2001 From: Ivan <2103732+codebien@users.noreply.github.com> Date: Fri, 24 Feb 2023 10:02:50 +0100 Subject: [PATCH 2/4] Print the expected char with the default output (cherry picked from commit 2305316831a5adfa7b32928baf2a703306c8d6bb) --- cmd/tests/cmd_run_test.go | 35 +++++++++++++++++++++++++++++++++++ cmd/ui.go | 12 +++++++++--- metrics/engine/ingester.go | 7 ++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/cmd/tests/cmd_run_test.go b/cmd/tests/cmd_run_test.go index 4280e89be621..c1cd82342e42 100644 --- a/cmd/tests/cmd_run_test.go +++ b/cmd/tests/cmd_run_test.go @@ -57,6 +57,7 @@ func TestSimpleTestStdin(t *testing.T) { cmd.ExecuteWithGlobalState(ts.GlobalState) stdout := ts.Stdout.String() + assert.Contains(t, stdout, "output: -") assert.Contains(t, stdout, "default: 1 iterations for each of 1 VUs") assert.Contains(t, stdout, "1 complete and 0 interrupted iterations") assert.Empty(t, ts.Stderr.Bytes()) @@ -1745,3 +1746,37 @@ func TestBrowserPermissions(t *testing.T) { }) } } + +func TestUIRenderOutput(t *testing.T) { + t.Parallel() + + tests := []struct { + outputs []string + expRender string + }{ + {outputs: []string{}, expRender: "output: -\n"}, + {outputs: []string{"json"}, expRender: "output: json(stdout)\n\n"}, + {outputs: []string{"json", "csv"}, expRender: "output: json(stdout), csv (file.csv)\n\n"}, + } + + for _, tc := range tests { + tc := tc + + t.Run(tc.expRender, func(t *testing.T) { + t.Parallel() + + ts := NewGlobalTestState(t) + ts.CmdArgs = []string{"k6", "run"} + for _, o := range tc.outputs { + ts.CmdArgs = append(ts.CmdArgs, "-o") + ts.CmdArgs = append(ts.CmdArgs, o) + } + ts.CmdArgs = append(ts.CmdArgs, "-") + ts.Stdin = bytes.NewBufferString(`export default function() {};`) + cmd.ExecuteWithGlobalState(ts.GlobalState) + + stdout := ts.Stdout.String() + assert.Contains(t, stdout, tc.expRender) + }) + } +} diff --git a/cmd/ui.go b/cmd/ui.go index ba5385686d6b..a2aaab725c16 100644 --- a/cmd/ui.go +++ b/cmd/ui.go @@ -19,6 +19,7 @@ import ( "go.k6.io/k6/cmd/state" "go.k6.io/k6/lib" "go.k6.io/k6/lib/consts" + "go.k6.io/k6/metrics/engine" "go.k6.io/k6/output" "go.k6.io/k6/ui/pb" ) @@ -109,11 +110,16 @@ func printExecutionDescription( switch { case outputOverride != "": outputDescriptions = []string{outputOverride} - case len(outputs) == 0: - outputDescriptions = []string{"-"} default: for _, out := range outputs { - outputDescriptions = append(outputDescriptions, out.Description()) + desc := out.Description() + if desc == engine.IngesterDescription { + if len(outputs) != 1 { + continue + } + desc = "-" + } + outputDescriptions = append(outputDescriptions, desc) } } diff --git a/metrics/engine/ingester.go b/metrics/engine/ingester.go index 83a514552a02..a8736af8c951 100644 --- a/metrics/engine/ingester.go +++ b/metrics/engine/ingester.go @@ -11,6 +11,11 @@ const collectRate = 50 * time.Millisecond var _ output.Output = &outputIngester{} +// IngesterDescription is a short description for ingester. +// This variable is used from a function in cmd/ui file for matching this output +// and print a special text. +const IngesterDescription = "Internal Metrics Ingester" + // outputIngester implements the output.Output interface and can be used to // "feed" the MetricsEngine data from a `k6 run` test run. type outputIngester struct { @@ -23,7 +28,7 @@ type outputIngester struct { // Description returns a human-readable description of the output. func (oi *outputIngester) Description() string { - return "engine" + return IngesterDescription } // Start the engine by initializing a new output.PeriodicFlusher From f8e745984c7972404b771436dd5e0e932fa956f6 Mon Sep 17 00:00:00 2001 From: na-- Date: Sat, 25 Feb 2023 06:08:32 -0800 Subject: [PATCH 3/4] Fix usage report block of k6 execution if it takes longer than 3s (#2938) (cherry picked from commit 4463298b07189bbfc7a7b58e0f1588a27b880b8f) --- cmd/run.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index cd70e6fab477..853613ee6d57 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -306,22 +306,17 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) { // Init has passed successfully, so unless disabled, make sure we send a // usage report after the context is done. if !conf.NoUsageReport.Bool { - backgroundProcesses.Add(2) - reportCtx, reportCancel := context.WithCancel(globalCtx) - reportDone := make(chan error) + backgroundProcesses.Add(1) go func() { + defer backgroundProcesses.Done() + reportCtx, reportCancel := context.WithTimeout(globalCtx, 3*time.Second) + defer reportCancel() logger.Debug("Sending usage report...") - reportDone <- reportUsage(reportCtx, execScheduler) - close(reportDone) - backgroundProcesses.Done() - }() - go func() { - select { - case <-reportDone: - case <-time.After(3 * time.Second): + if rerr := reportUsage(reportCtx, execScheduler); rerr != nil { + logger.WithError(rerr).Debug("Error sending usage report") + } else { + logger.Debug("Usage report sent successfully") } - reportCancel() - backgroundProcesses.Done() }() } From af3a0b89ece6398484fff14fb6f5918711869e69 Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Mon, 27 Feb 2023 11:20:52 +0200 Subject: [PATCH 4/4] Release k6 v0.43.1 --- lib/consts/consts.go | 2 +- release notes/v0.43.1.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 release notes/v0.43.1.md diff --git a/lib/consts/consts.go b/lib/consts/consts.go index 441690fc2ccc..691d21a0a842 100644 --- a/lib/consts/consts.go +++ b/lib/consts/consts.go @@ -8,7 +8,7 @@ import ( ) // Version contains the current semantic version of k6. -const Version = "0.43.0" +const Version = "0.43.1" // VersionDetails can be set externally as part of the build process var VersionDetails = "" //nolint:gochecknoglobals diff --git a/release notes/v0.43.1.md b/release notes/v0.43.1.md new file mode 100644 index 000000000000..061d21082816 --- /dev/null +++ b/release notes/v0.43.1.md @@ -0,0 +1,4 @@ +k6 v0.43.1 is a patch release containing a few bugfixes: +- [#2926](https://github.com/grafana/k6/pull/2926) fixed a panic in `setup()` code when `vu.iterationInScenario` from `k6/execution` was used. +- [#2934](https://github.com/grafana/k6/pull/2934) fixed a wrongly printed internal output ID to the `stdout` UI. +- [#2938](https://github.com/grafana/k6/pull/2938) fixed a synchronization bug that caused k6 to get stuck after the end-of-test summary when sending the usage report took more than 3s. Thanks for [reporting this](https://github.com/grafana/k6/issues/2937), @ichasepucks! \ No newline at end of file