Skip to content

Commit

Permalink
Remove detected leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed Dec 23, 2022
1 parent 3dbeb3b commit ab92a6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
6 changes: 2 additions & 4 deletions cmd/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,10 +1482,8 @@ func TestPrometheusRemoteWriteOutput(t *testing.T) {

ts := newGlobalTestState(t)
ts.args = []string{"k6", "run", "--out", "experimental-prometheus-rw", "-"}
ts.stdIn = bytes.NewBufferString(`
import exec from 'k6/execution';
export default function () {};
`)
ts.envVars["K6_PROMETHEUS_RW_SERVER_URL"] = "http://a-fake-url-for-fail"
ts.stdIn = bytes.NewBufferString(`export default function () {};`)

newRootCommand(ts.globalState).execute()
ts.outMutex.Lock()
Expand Down
25 changes: 11 additions & 14 deletions lib/testutils/httpmultibin/httpmultibin.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,15 @@ type jsonBody struct {
Compression string `json:"compression"`
}

func getWebsocketHandler(echo bool, closePrematurely bool) http.Handler {
func getWebsocketHandler(t testing.TB, echo bool, closePrematurely bool) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
conn, err := (&websocket.Upgrader{}).Upgrade(w, req, w.Header())
if err != nil {
return
}
require.NoError(t, err)

defer func() {
_ = conn.Close()
}()

if echo {
messageType, r, e := conn.NextReader()
if e != nil {
Expand All @@ -116,12 +119,6 @@ func getWebsocketHandler(echo bool, closePrematurely bool) http.Handler {
if !closePrematurely {
closeMsg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")
_ = conn.WriteControl(websocket.CloseMessage, closeMsg, time.Now().Add(time.Second))
// Wait for response control frame
<-time.After(time.Second)
}
err = conn.Close()
if err != nil {
return
}
})
}
Expand Down Expand Up @@ -256,10 +253,10 @@ func NewHTTPMultiBin(t testing.TB) *HTTPMultiBin {
// Create a http.ServeMux and set the httpbin handler as the default
mux := http.NewServeMux()
mux.Handle("/brotli", getEncodedHandler(t, "br"))
mux.Handle("/ws-echo", getWebsocketHandler(true, false))
mux.Handle("/ws-echo-invalid", getWebsocketHandler(true, true))
mux.Handle("/ws-close", getWebsocketHandler(false, false))
mux.Handle("/ws-close-invalid", getWebsocketHandler(false, true))
mux.Handle("/ws-echo", getWebsocketHandler(t, true, false))
mux.Handle("/ws-echo-invalid", getWebsocketHandler(t, true, true))
mux.Handle("/ws-close", getWebsocketHandler(t, false, false))
mux.Handle("/ws-close-invalid", getWebsocketHandler(t, false, true))
mux.Handle("/zstd", getEncodedHandler(t, "zstd"))
mux.Handle("/zstd-br", getZstdBrHandler(t))
mux.Handle("/", httpbin.New().Handler())
Expand Down

0 comments on commit ab92a6c

Please sign in to comment.