1

I am looking for a way, where for the below code next user comes in action only if current user is done with all of the tasks mentioned in a sequence. That is user should not be switched unless all tasks in sequence is completed for one user:

from locust import HttpUser,task,SequentialTaskSet,wait_time

@task 
def One(self):
 print("One")
 self.client.get(url="https://www.google.com")

@task
def Two(self):
print("Two")
self.client.get(url="https://www.google.com")

@task
def Three(self):
print("Three")
self.client.get(url="https://www.google.com")

@task
def Four(self):
print("Four") 
self.client.get(url="https://www.google.com")   
   
class mysequence(SequentialTaskSet):     
@task
def myseq(self):
   
  One(self)
  Two(self)
  Three(self)
  Four(self)

class abc(HttpUser):
 wait_time(0,1)
 tasks=[mysequence]

As of with this code, user is getting spawned before previous user is done with all its tasks mentioned in the sequence. Please refer below trace:

PS C:\Users\abhijeet.goswami\src> locust -f tests/serial.py -u 5 -r 1 --host 
https://prudent-plus-staging.prudentbrokers.in/ --run-time 10s --headless --only-summary 
[2025-02-19 13:30:29,786] PGNPF3TAKACLT/INFO/locust.main: Starting Locust 2.32.5
[2025-02-19 13:30:29,786] PGNPF3TAKACLT/INFO/locust.main: Run time limit set to 10 seconds
[2025-02-19 13:30:29,786] PGNPF3TAKACLT/INFO/locust.runners: Ramping to 5 users at a rate of 1.00 per second
One
Two
One
Three
Two
One
Four
Three
Two
One
Four
[2025-02-19 13:30:33,835] PGNPF3TAKACLT/INFO/locust.runners: All users spawned: {"abc": 5} (5 total users)
One
Two
Three
4
  • @hayman kindly help Commented Feb 21 at 6:48
  • 1
    Hi Hayman! My number one recommendation is: Dont use SequentialTaskSet, just use a single task and write code yourself instead. Commented Feb 22 at 16:53
  • 1
    Many thanks , i'm trying to improvise this :) Commented Feb 22 at 17:33
  • what about using just one user? You will end up with the same user making N "mysequence" calls Commented Aug 29 at 6:39

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.