I’m trying to use k6 for the first time, and run some initial tests.
I have a very simple test which sets some session cookies and then hits an endpoint.
The session tokens that are used in the test come from a json endpoint provided by our test system, and these change every time the system is deployed, so the test needs to get them from this endpoint at the point the test runs.
Currently I am making the request to the sessions endpoint in the ‘setup’ function in k6, making them available to my test from there. BUT when I’m running a test with just 200 VUs, k6 is consuming all of the 16GBs of memory on the box before it’s even finished ramping up, and then crashing.
I’ve realised from some googling that this is because every VU gets it’s own copy of the data from setup, rather than this being shared, which I did not expect. And because we are returning 50,000 sessions (where the tests will need to get to eventually), this is using a lot of memory.
I’ve tried to change tact and use the SharedArray. However this only seems to have loading data from files in mind, not endpoints.
When I try to make a http request in the SharedArray callback, I get the error ‘GoError: Making http requests in the init context is not supported’.
When I try to create the SharedArray inside setup, I get ’ GoError: new SharedArray must be called in the init context’
Does anyone know of a way to use these two things together, or an alternative approach that will work?