Open websocket connections on setup method

I’m trying to implement a load test in K6 for a distributed application that consists of a bunch of nodes sending messages to each other. In the setup method, I’m gathering the list of nodes available in the infrastructure that will participate in the load test, and pass all the required information to the default function. The default function choses one node randomly and send an http request to another node randomly.

The issue that I’m facing is that the http request is async. The http response it is only the acknowledge of the receiving the request. The test should check that the message was correctly processed and its latency. For doing that the receiving node is offering a websocket where the sender can subscribe.

I have implemented the K6 websocket following the guide(WebSockets), but the downside of that approach is that the websocket connection is opened in every iteration with the extra cost that this entails to the node. I tried moving the implementation to the setup function but it does not work either because at that point there are no messages being sent, and then the code gets halted on the ‘open’ handler waiting for the messages to arrive, and the websocket terminates abruptly because no messages are coming.

I cannot use the websocket strategy defined on the guide because the node get saturated with not being able to open/close websocket connections so quickly. In the real scenario the opening and closing of websockets only happens once, when the node enters or exists the network of nodes.
Is there an alternative implementation for this kind of test?

Hi
Do the multiple scenarios address your issue? Advanced Examples
Where you could have 2 scenarios running at the same time
1st - opens socket connection and checks messages
2nd - makes requests to trigger events for opened socket

1 Like