0

I have two user classes:

  1. SyncUser
  2. NormalUser

with the following code:

class syncUser(HttpUser):
    host = '<hostname>'
    def on_start(self):
        self.userId = getsyncPullUser()
        self.headers = {
            "Content-Type": "application/json"
        }

    @task
    def SyncUser(self):
        timeout=10
        params = {
            "timeout":timeout,
        }
        while True:
            response = self.client.get("/sync/api", headers = self.headers, params = params, name="GET_sync/api")


class NormalUser(HttpUser):
    host = '<hostname>'

    def on_start(self):
        self.userId = getuser()
        self.headers = {
            "Content-Type": "application/json",
        }

    @task
    def getmessages(self):
        params = {
            "status":"ACCEPTED",
            "source":"postman"
        }

        self.client.get("/<api>", headers = self.headers, params = params, name="GET /<api>")


I want to create NormalUser after SyncUser. This is done to make sure the userIds assigned to NormalUser(using getuser()) are a subset of users assigned to SyncUser (using getsyncPullUser()).

Need help in how to do this.

If there is a way to run multiple tasks simultaneously, that also solves my problem, as I will run the syncUser function in parallel and I won't need a new class.

6
  • Hi aa! Your question is a little long and hard to read. Can you clarify and make it shorter? I'd love to help you but I don't want to resort to guessing at what you mean... Commented Aug 29, 2024 at 7:40
  • Hi @Cyberwiz I have tried to include some code and make it simpler. Please let me know which part is difficult to understand. Commented Aug 29, 2024 at 9:05
  • Here's an example of how to do things in parallel in one user: docs.locust.io/en/latest/increase-performance.html#concurrency I think it works for HttpUser as well, but if not, try switching to FastHttpUser Commented Aug 30, 2024 at 10:28
  • for my requirement, the above solution might not work. example scenario: Task1 : runs indefinitely Task2: start and complete. start again when scheduled Task3: start and complete. start again when scheduled So the concurrency I would want is task1 runs indefinitely, but task2 and task3 can switch amongst themselves, according to the weights assigned to them . Commented Aug 30, 2024 at 19:57
  • 1
    This worked for me, Thanks Commented Sep 6, 2024 at 6:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.