From ff794711e41265357052da2d7b622d1d2f126406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Mon, 9 Sep 2019 17:53:48 +0200 Subject: [PATCH 1/3] fix(core,test): correct "greater than" test error message --- core/engine_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/engine_test.go b/core/engine_test.go index 7c07ada109c..cd81f8519b0 100644 --- a/core/engine_test.go +++ b/core/engine_test.go @@ -618,10 +618,10 @@ func TestSentReceivedMetrics(t *testing.T) { reuseSent, reuseReceived := runTest(t, ts, tc, false) if noReuseSent < reuseSent { - t.Errorf("noReuseSent=%f is greater than reuseSent=%f", noReuseSent, reuseSent) + t.Errorf("reuseSent=%f is greater than noReuseSent=%f", reuseSent, noReuseSent) } if noReuseReceived < reuseReceived { - t.Errorf("noReuseReceived=%f is greater than reuseReceived=%f", noReuseReceived, reuseReceived) + t.Errorf("reuseReceived=%f is greater than noReuseReceived=%f", reuseReceived, noReuseReceived) } } } From 843f71f76b6061c4e9aa4a82c45455068c88de86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Mon, 9 Sep 2019 18:23:22 +0200 Subject: [PATCH 2/3] fix(core,test): update WebSocket URLs --- core/engine_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/engine_test.go b/core/engine_test.go index cd81f8519b0..642b6fc8a0a 100644 --- a/core/engine_test.go +++ b/core/engine_test.go @@ -540,7 +540,7 @@ func TestSentReceivedMetrics(t *testing.T) { {tr(`import ws from "k6/ws"; let data = "0123456789".repeat(100); export default function() { - ws.connect("ws://HTTPBIN_IP:HTTPBIN_PORT/ws-echo", null, function (socket) { + ws.connect("WSBIN_URL/ws-echo", null, function (socket) { socket.on('open', function open() { socket.send(data); }); @@ -667,7 +667,7 @@ func TestRunTags(t *testing.T) { }) group("websockets", function() { - var response = ws.connect("wss://HTTPSBIN_IP:HTTPSBIN_PORT/ws-echo", params, function (socket) { + var response = ws.connect("WSBIN_URL/ws-echo", params, function (socket) { socket.on('open', function open() { console.log('ws open and say hello'); socket.send("hello"); From ae564fd49e5cc72b6b1fc6af686e6c187b536bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Mon, 9 Sep 2019 18:23:47 +0200 Subject: [PATCH 3/3] fix(test): close WebSocket connection in Echo handler This _should_ fix flaky test `TestSentReceivedMetrics`. See https://circleci.com/gh/loadimpact/k6/6474, https://circleci.com/gh/loadimpact/k6/6484 . This issue was introduced in a63bb586 (PR #1138), where the previous implementation of `getWebsocketEchoHandler()` closed the connection after writing, so this change brings that back. It seems that closing the connection creates additional metrics which `TestSentReceivedMetrics` takes into account _sometimes_, hence the flakiness. From discussions with @na--, we agreed to remove the persistent connection implementation of a63bb586 (the `for` loop here) since that matches the previous version, but we'll create a new WS test that tests multiple message passing, since none of our current tests seem to do this. --- lib/testutils/httpmultibin/httpmultibin.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/testutils/httpmultibin/httpmultibin.go b/lib/testutils/httpmultibin/httpmultibin.go index dff179b7d7f..f6ff7039c82 100644 --- a/lib/testutils/httpmultibin/httpmultibin.go +++ b/lib/testutils/httpmultibin/httpmultibin.go @@ -106,15 +106,17 @@ func websocketEchoHandler(w http.ResponseWriter, req *http.Request) { return } - for { - mt, message, err := conn.ReadMessage() - if err != nil { - break - } - err = conn.WriteMessage(mt, message) - if err != nil { - break - } + mt, message, err := conn.ReadMessage() + if err != nil { + return + } + err = conn.WriteMessage(mt, message) + if err != nil { + return + } + err = conn.Close() + if err != nil { + return } }