Skip to content

Commit

Permalink
Update: locustfile to Locust v1.3.1
Browse files Browse the repository at this point in the history
Adapt the classes and attributes to work with Locust v1.3.1
  • Loading branch information
AndresJRamirez committed Oct 27, 2020
1 parent a27bd66 commit 7255015
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions loadtest/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from random import choice

from locust import (
HttpLocust,
TaskSequence,
HttpUser,
SequentialTaskSet,
TaskSet,
seq_task,
task,
between
)


Expand All @@ -22,29 +22,27 @@ def index(self):
self.client.get("/visualizer/{0}/".format(VOTING))


class DefVoters(TaskSequence):
class DefVoters(SequentialTaskSet):

def on_start(self):
with open('voters.json') as f:
self.voters = json.loads(f.read())
self.voter = choice(list(self.voters.items()))

def on_quit(self):
self.voter = None

@seq_task(1)
@task
def login(self):
username, pwd = self.voter
self.token = self.client.post("/authentication/login/", {
"username": username,
"password": pwd,
}).json()

@seq_task(2)
@task
def getuser(self):
self.user = self.client.post("/authentication/getuser/", self.token).json()
self.usr= self.client.post("/authentication/getuser/", self.token).json()
print( str(self.user))

@seq_task(3)
@task
def voting(self):
headers = {
'Authorization': 'Token ' + self.token.get('token'),
Expand All @@ -56,16 +54,22 @@ def voting(self):
"a": "12",
"b": "64"
},
"voter": self.user.get('id'),
"voter": self.usr.get('id'),
"voting": VOTING
}), headers=headers)


class Visualizer(HttpLocust):
def on_quit(self):
self.voter = None

class Visualizer(HttpUser):
host = HOST
task_set = DefVisualizer
tasks = [DefVisualizer]
wait_time = between(3,5)



class Voters(HttpLocust):
class Voters(HttpUser):
host = HOST
task_set = DefVoters
tasks = [DefVoters]
wait_time= between(3,5)

0 comments on commit 7255015

Please sign in to comment.