k6

A modern load testing tool, using Go and JavaScript

"like unit testing, for performance"

k6 is a modern load testing tool, building on Load Impact's years of experience. It provides a clean, approachable JavaScript scripting API, distributed and cloud execution, and orchestration via a REST API.

Get Started    Documentation

Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

The ws module implements WebSocket support in k6.

Methods
Description

Create a WebSocket connection to a remote host.

connect() takes a "run" function as its third parameter, and that function should accept a Socket object as its only parameter. The run function will be called immediately when the WebSocket connection is created, execute all code inside it, and then block until the WebSocket connection is closed (by the remote host or by using socket.close()).

import ws from "k6/ws";

export default function() {
  var url = "ws://echo.websocket.org";
  var resp = ws.connect(url, null, function(socket) {
    socket.on('open', function() {
      console.log("WebSocket connection established!");
      socket.close();
    });
  });
};
socket methods
Description

Set up callbacks for various WebSocket events.

Call a function with a delay.

Call a function repeatedly at certain intervals.

Close WebSocket connection.

k6/ws