Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giving cookie to WebSocket test #232

Open
Inateno opened this issue Dec 21, 2016 · 6 comments
Open

Giving cookie to WebSocket test #232

Inateno opened this issue Dec 21, 2016 · 6 comments

Comments

@Inateno
Copy link

Inateno commented Dec 21, 2016

Hi,

I'm trying to benchmark a WebSocket but I can't find in the documentation how to set the cookie.

Any help ?

Thanks

@hassy
Copy link
Member

hassy commented Dec 21, 2016

@Inateno I think this should work but I haven't tested it:

config:
  target: "some-target"
  ws:
    headers:
      Cookie: "cookievalue"
scenarios:
  # ...

But if that works, it would set the same cookie for all virtual users. There's no support for setting cookies inside scenarios yet.

@Inateno
Copy link
Author

Inateno commented Dec 23, 2016

No problem, testing with one user is ok. I'm gonna try this now.

@jamesjieye
Copy link

@hassy Is the any plan when to add support of setting cookie per users?

I'm testing a socket.io application and there are multiple servers behind a load balancer. The load balancer will use sticky session by routing the requests to the same server with the value in the cookie.

Thank you

@hassy
Copy link
Member

hassy commented Jan 24, 2017

Not planned for any particular time at the moment @jamesjieye - PRs gladly accepted though.

@maxjanisse
Copy link

I just encountered this same need and did some local hacking to see what I could figure out, if anything. Thankfully, it turns out that more recent versions of socket.io (1.5.2+) now support adding extra headers via the "extraHeaders" option during creation of the Socket (see here). I've been able to confirm that updating Artillery's socket.io to the latest version (1.7.2) and adding in the new option works like a charm. Admittedly, I'm doing this work on a Windows box, so I can't run the provided unit tests to ensure I haven't destroyed something.

As far as implementing this feature, the only drawback/caveat seems to be that the extra headers will only be applied once the first emit is encountered in the scenario flow. This means the actual setting of these headers and cookies needs to happen at the step-level, but only the first collection will actually be used. This leads me to think that the definition of these headers should probably be set at the scenario-level, but only evaluated once that first emit is encountered.

I've forked the repository and am planning on putting together a PR for this issue once I'm happy with the implementation.

@rstormsf
Copy link

Here is what worked for me:

config:
  target: 'http://localhost:8123'
  socketio:
    transports: ["websocket"]
    extraHeaders:
      Cookie: "name=Roman;"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants