I am total newbie to Python. I am writing my first Python class this week to run Locust.io load test on our API. I have setup the code below.
import random
from locust import HttpUser, SequentialTaskSet, task, between
from datetime import datetime
class CredentialLoadTest(SequentialTaskSet):
@task
def post_credential(self):
print("==========================")
print("========== POST ==========")
print("==========================")
print("==========POST END===========")
@task
def get_credential(self):
print("==========================")
print("========== GET ===========")
print("==========================")
print("==========GET END===========")
@task
def put_credential(self):
print("==========================")
print("========== PUT ===========")
print("==========================")
print("==========PUT END===========")
class AwesomeUser(HttpUser):
tasks = [CredentialLoadTest]
host = "https://url.com"
# wait time between tasks, 5 and 9 seconds
wait_time = between(5, 9)
I have removed all of the actual testing code for my API endpoints here. I just simply wanted to validate if the tasks are running sequentially. When I run this code I get the output shown below.
[2020-07-29 21:14:54,067] 8a7f07ddbe29/INFO/locust.main: Starting web
interface at http://:8089 [2020-07-29 21:14:54,077]
8a7f07ddbe29/INFO/locust.main: Starting Locust 1.1 [2020-07-29
21:15:01,123] 8a7f07ddbe29/INFO/locust.runners: Hatching and swarming
2 users at the rate 2 users/s (0 users already running)...
==========================
========== GET ===========
==========================
==========GET END=========== [2020-07-29 21:15:01,624] 8a7f07ddbe29/INFO/locust.runners: All users hatched: AwesomeUser: 2 (0
already running)
==========================
========== GET ===========
==========================
==========GET END===========
==========================
========== POST ==========
==========================
==========POST END===========
==========================
========== POST ==========
==========================
==========POST END===========
==========================
========== PUT ===========
==========================
==========PUT END===========
==========================
========== PUT ===========
==========================
==========PUT END===========
==========================
========== GET ===========
==========================
==========GET END===========
==========================
========== GET ===========
==========================
==========GET END===========
As you can see the order of tasks running is GET, POST PUT. The order I want is POST, GET and PUT.