0

I provide number of users=12 and hatch rate=2. How can I get user id(s) of all users hitting my web page, as I would like to do some customizations based on the object names which are getting created (say an article title).

How to pass user information (say user id) while creating new articles. So that if I run a test with 12 users, I would know that articles were created by a certain user.

from locust import HttpLocust, TaskSet, task

def create_new_article(self):
       with self.client.request('post',"/articles",data={"article[title]":"computer","article[content]":"pc"},catch_response=True) as response:   
       print response          
selvi
  • 1,271
  • 2
  • 21
  • 41

1 Answers1

0

How can I get user id(s) of all users hitting my web page?

This depends on how your web server is set up. What exactly is a user ID in your application's context?

I'll proceed with the assumption that you have some mechanism by which you can generate a user ID.

You could have your client side get the user ID(s) (using Javascript for example) and then pass each ID along to the server in a HTTP request where you could custom define a header to contain your user ID for that request.

For example, if you're using Flask/Python to handle all the business logic of your web application, then you might have some code like:

from flask import Flask, request
app = Flask(__name__)

@app.route("/articles")
def do_something_with_user_id():
    do_something(request.headers.get("user-id"))

if __name__ == "__main__":
    app.run()

How to pass user information (say user id) while creating new articles?

You could change your POST request line in your Locust script to something like:

with self.client.request('post',"/articles",headers=header_with_user_id,data={"article[title]":"computer","article[content]":"pc"},catch_response=True) as response:

where header_with_user_id could be defined as follows:

header_with_user_id = { "user-id": <some user ID>}

where <some user ID> would be a stringified version of whatever your mechanism to obtain the user ID gets you.

Anish Ramaswamy
  • 2,326
  • 3
  • 32
  • 63