I am trying to load test a websocket server where I want to add a JSON Web Token (JWT) as a header which is different per user – and that gets passed when establishing the connection.
Here are the files
processor.js
let tokens = [
"token1",
"token2,
"token3"
]
function generateRandomToken (userContext, events, done) {
userContext.vars.token = tokens[Math.floor(Math.random() * tokens.length)];
return done()
}
module.exports = {
generateRandomToken
};
Here is the main yaml file where the load test script is executed
config:
target: "ws://localhost:8080/userMessages"
phases:
- duration: 1
arrivalRate: 1
processor: "./processor.js"
function: "generateRandomToken"
ws:
headers:
x-jwt-token: "{{ token }}"
scenarios:
- engine: "ws"
flow:
- send: "Test message"
- think: 30
The error that I am getting when executing this is worker error, id: 1 TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "x-jwt-token"
I see there is a similar issue open here for socketio – it is closed but without any answer – https://github.com/artilleryio/artillery/issues/2003
I am expecting a proper token to be generated on each request.
devde is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.