Skip to content

Commit

Permalink
fix(test): close WebSocket connection in Echo handler
Browse files Browse the repository at this point in the history
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 a63bb58 (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 a63bb58 (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.
  • Loading branch information
Ivan Mirić committed Sep 11, 2019
1 parent 843f71f commit ae564fd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/testutils/httpmultibin/httpmultibin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit ae564fd

Please sign in to comment.