From d36e82bf581bbc49c4cd28be29dd5c34ee27c4d9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:25:47 +0000 Subject: [PATCH] Upgrade experimental module (deps): Bump github.com/grafana/xk6-websockets Bumps [github.com/grafana/xk6-websockets](https://github.com/grafana/xk6-websockets) from 0.3.0 to 0.4.0. - [Commits](https://github.com/grafana/xk6-websockets/compare/v0.3.0...v0.4.0) --- updated-dependencies: - dependency-name: github.com/grafana/xk6-websockets dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +-- .../xk6-websockets/websockets/websockets.go | 28 ++++++++++++++++--- vendor/modules.txt | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 5912d649f93..3adee57ce9f 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/grafana/xk6-output-prometheus-remote v0.3.1 github.com/grafana/xk6-redis v0.2.0 github.com/grafana/xk6-webcrypto v0.2.1 - github.com/grafana/xk6-websockets v0.3.0 + github.com/grafana/xk6-websockets v0.4.0 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/influxdata/influxdb1-client v0.0.0-20190402204710-8ff2fc3824fc github.com/jhump/protoreflect v1.15.6 diff --git a/go.sum b/go.sum index eb6e965c23d..1969f4795ef 100644 --- a/go.sum +++ b/go.sum @@ -106,8 +106,8 @@ github.com/grafana/xk6-redis v0.2.0 h1:iXmAKVlAxafZ/h8ptuXTFhGu63IFsyDI8QjUgWm66 github.com/grafana/xk6-redis v0.2.0/go.mod h1:B3PA9PAPJa2/WUfNJCdQwZrbb6D4e6UHIk8dssQbj7w= github.com/grafana/xk6-webcrypto v0.2.1 h1:gKC8TD9HQMSNxfJ3CLAyf/CYVnDnHeHi1j5peXyArBI= github.com/grafana/xk6-webcrypto v0.2.1/go.mod h1:K1TAPNbQAvNb/0heG1+K7wLPOe9353w9a8GcBsiHTx4= -github.com/grafana/xk6-websockets v0.3.0 h1:qxOTfjvY+FHvQ89Zn3m9FW88mz0mo+x714A94ssq+l0= -github.com/grafana/xk6-websockets v0.3.0/go.mod h1:v2Xlz0J2QTtWmVfVyuUQpK1juuK+NU/2zJP8RyP5eNU= +github.com/grafana/xk6-websockets v0.4.0 h1:gK0ekd7nIO4tPDzWk4ljQGzMep5Usy3Y/iuXZM7xXHI= +github.com/grafana/xk6-websockets v0.4.0/go.mod h1:sykcMskoS8qA8/XWED5h7qg7xsJXqzdKYOM0+inAz9s= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 h1:Wqo399gCIufwto+VfwCSvsnfGpF/w5E9CNxSwbpD6No= diff --git a/vendor/github.com/grafana/xk6-websockets/websockets/websockets.go b/vendor/github.com/grafana/xk6-websockets/websockets/websockets.go index 3312dc4526f..4651be0a6b2 100644 --- a/vendor/github.com/grafana/xk6-websockets/websockets/websockets.go +++ b/vendor/github.com/grafana/xk6-websockets/websockets/websockets.go @@ -83,6 +83,7 @@ type webSocket struct { // fields that should be seen by js only be updated on the event loop readyState ReadyState bufferedAmount int + binaryType string } type ping struct { @@ -146,6 +147,11 @@ func parseURL(urlValue goja.Value) (*url.URL, error) { return url, nil } +const ( + arraybufferBinaryType = "arraybuffer" + blobBinaryType = "blob" +) + // defineWebsocket defines all properties and methods for the WebSocket func defineWebsocket(rt *goja.Runtime, w *webSocket) { must(rt, w.obj.DefineDataProperty( @@ -168,10 +174,17 @@ func defineWebsocket(rt *goja.Runtime, w *webSocket) { // protocol must(rt, w.obj.DefineAccessorProperty( "binaryType", rt.ToValue(func() goja.Value { - return rt.ToValue("ArrayBuffer") - }), rt.ToValue(func() goja.Value { - common.Throw(rt, errors.New("binaryType is not settable in k6 as it doesn't support Blob")) - return nil // it never gets to here + return rt.ToValue(w.binaryType) + }), rt.ToValue(func(s string) error { + switch s { + case blobBinaryType: + return errors.New("blob is currently not supported, only arraybuffer is") + case arraybufferBinaryType: + w.binaryType = s + return nil + default: + return fmt.Errorf("unknown binaryType %s, the supported one is arraybuffer", s) + } }), goja.FLAG_FALSE, goja.FLAG_TRUE)) setOn := func(property string, el *eventListener) { @@ -382,6 +395,9 @@ func (w *webSocket) loop() { } } +const binarytypeWarning = `You have not set a Websocket binaryType to "arraybuffer", but you got a binary response. ` + + `This has been done automatically now, but in the future this will not work.` + func (w *webSocket) queueMessage(msg *message) { w.tq.Queue(func() error { if w.readyState != OPEN { @@ -402,6 +418,10 @@ func (w *webSocket) queueMessage(msg *message) { ev := w.newEvent(events.MESSAGE, msg.t) if msg.mtype == websocket.BinaryMessage { + if w.binaryType == "" { + w.binaryType = arraybufferBinaryType + w.vu.State().Logger.Warn(binarytypeWarning) + } // TODO this technically could be BLOB , but we don't support that ab := rt.NewArrayBuffer(msg.data) must(rt, ev.DefineDataProperty("data", rt.ToValue(ab), goja.FLAG_FALSE, goja.FLAG_FALSE, goja.FLAG_TRUE)) diff --git a/vendor/modules.txt b/vendor/modules.txt index 3214f41c0ce..ff82cae8957 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -187,7 +187,7 @@ github.com/grafana/xk6-redis/redis # github.com/grafana/xk6-webcrypto v0.2.1 ## explicit; go 1.19 github.com/grafana/xk6-webcrypto/webcrypto -# github.com/grafana/xk6-websockets v0.3.0 +# github.com/grafana/xk6-websockets v0.4.0 ## explicit; go 1.18 github.com/grafana/xk6-websockets/websockets github.com/grafana/xk6-websockets/websockets/events