I’d love to know the answer to this too. I’ve been trying to get K6 going for a few hours and keep getting the:
[debug] LiveView session was misconfigured or the user token is outdated.
1) Ensure your session configuration in your endpoint is in a module attribute:
@session_options [
...
]
2) Change the `plug Plug.Session` to use said attribute:
plug Plug.Session, @session_options
3) Also pass the `@session_options` to your LiveView socket:
socket "/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [session: @session_options]]
4) Define the CSRF meta tag inside the `<head>` tag in your layout:
<%= csrf_meta_tag() %>
5) Pass it forward in your app.js:
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}});
But I’m going through the login and sending to csrfToken along with it. Seems to be close but I’m missing something to get it to finalize the handshake.
FYI we experimented load testing channels and liveview using K6 with some degree of success.
We built a library at last year’s SpawnFest to easily generate and run K6 load tests for a variety of scenarios, including channels and liveviews.
Support for channels and liveviews is still experimental though and could definitely be improved, but if anyone is looking for a starting point to build on (and maybe contribute back ) the repo can be found here.