diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index 3a90822a25b..dd77f6e474c 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -320,6 +320,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/v') env: VERSION: ${{ needs.configure.outputs.version }} + HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }} steps: - name: Download source code archive run: curl -fsSL "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/archive/${VERSION}.tar.gz" -o "${VERSION}.tar.gz" diff --git a/lib/consts/consts.go b/lib/consts/consts.go index 85f40159fe7..df6833325ba 100644 --- a/lib/consts/consts.go +++ b/lib/consts/consts.go @@ -28,7 +28,7 @@ import ( ) // Version contains the current semantic version of k6. -const Version = "0.31.0" +const Version = "0.31.1" // VersionDetails can be set externally as part of the build process var VersionDetails = "" // nolint:gochecknoglobals diff --git a/lib/netext/httpext/request_test.go b/lib/netext/httpext/request_test.go index d3716f0bfd8..c71c754280d 100644 --- a/lib/netext/httpext/request_test.go +++ b/lib/netext/httpext/request_test.go @@ -31,12 +31,16 @@ import ( "testing" "time" + "github.com/mccutchen/go-httpbin/httpbin" + "github.com/oxtoacart/bpool" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" "github.com/loadimpact/k6/lib" + "github.com/loadimpact/k6/lib/metrics" "github.com/loadimpact/k6/stats" ) @@ -280,3 +284,68 @@ func BenchmarkWrapDecompressionError(b *testing.B) { _ = wrapDecompressionError(err) } } + +func TestTrailFailed(t *testing.T) { + t.Parallel() + srv := httptest.NewTLSServer(httpbin.New().Handler()) + defer srv.Close() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + samples := make(chan stats.SampleContainer, 10) + logger := logrus.New() + logger.Level = logrus.DebugLevel + state := &lib.State{ + Options: lib.Options{ + RunTags: &stats.SampleTags{}, + SystemTags: &stats.DefaultSystemTagSet, + }, + Transport: srv.Client().Transport, + Samples: samples, + Logger: logger, + BPool: bpool.NewBufferPool(2), + } + ctx = lib.WithState(ctx, state) + + testCases := map[string]struct { + responseCallback func(int) bool + failed null.Bool + }{ + "null responsecallback": {responseCallback: nil, failed: null.NewBool(false, false)}, + "unexpected response": {responseCallback: func(int) bool { return false }, failed: null.NewBool(true, true)}, + "expected response": {responseCallback: func(int) bool { return true }, failed: null.NewBool(false, true)}, + } + for name, testCase := range testCases { + responseCallback := testCase.responseCallback + failed := testCase.failed + + t.Run(name, func(t *testing.T) { + req, _ := http.NewRequest("GET", srv.URL, nil) + preq := &ParsedHTTPRequest{ + Req: req, + URL: &URL{u: req.URL, URL: srv.URL}, + Body: new(bytes.Buffer), + Timeout: 10 * time.Millisecond, + ResponseCallback: responseCallback, + } + res, err := MakeRequest(ctx, preq) + + require.NoError(t, err) + assert.NotNil(t, res) + assert.Len(t, samples, 1) + sample := <-samples + trail := sample.(*Trail) + require.Equal(t, failed, trail.Failed) + + var httpReqFailedSampleValue null.Bool + for _, s := range sample.GetSamples() { + if s.Metric.Name == metrics.HTTPReqFailed.Name { + httpReqFailedSampleValue.Valid = true + if s.Value == 1.0 { + httpReqFailedSampleValue.Bool = true + } + } + } + require.Equal(t, failed, httpReqFailedSampleValue) + }) + } +} diff --git a/lib/netext/httpext/transport.go b/lib/netext/httpext/transport.go index 6c77648b056..381ce6180a7 100644 --- a/lib/netext/httpext/transport.go +++ b/lib/netext/httpext/transport.go @@ -187,7 +187,7 @@ func (t *transport) measureAndEmitMetrics(unfReq *unfinishedRequest) *finishedRe finalTags := stats.IntoSampleTags(&tags) trail.SaveSamples(finalTags) if t.responseCallback != nil { - trail.Failed.SetValid(true) + trail.Failed.Valid = true if failed == 1 { trail.Failed.Bool = true } diff --git a/release notes/v0.31.1.md b/release notes/v0.31.1.md new file mode 100644 index 00000000000..57d78debf37 --- /dev/null +++ b/release notes/v0.31.1.md @@ -0,0 +1,3 @@ +k6 v0.31.1 is a patch release with a single bugfix. + +The bugfix is about the cloud output and the new `http_req_failed` metric in k6 v0.31.0. Due to additional state being used for its transport to the k6 cloud, and a misunderstanding of what a functional call from a library dependency does, the `http_req_failed` values were always set to `1`. This did not affect any other output or the end of test summary. ([#1908](https://github.com/loadimpact/k6/issues/1908))