Skip to content

Commit

Permalink
Rizal expose client index to locust, so user can access it in the tes…
Browse files Browse the repository at this point in the history
…t file (locustio#59)

* expose client index to locust, so user can access it in the test file

* update logger info
  • Loading branch information
Rizal Fauzi Rahman authored and pancaprima committed Apr 24, 2018
1 parent 8ed35c8 commit 62d68be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions locust/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class Locust(object):
client = NoClientWarningRaiser()
_catch_exceptions = True

def __init__(self):
super(Locust, self).__init__()
def __init__(self, runner=None):
self.runner = runner

def run(self):
try:
Expand Down Expand Up @@ -126,8 +126,8 @@ class HttpLocust(Locust):
The client support cookies, and therefore keeps the session between HTTP requests.
"""

def __init__(self):
super(HttpLocust, self).__init__()
def __init__(self, runner=None):
super(HttpLocust, self).__init__(runner=runner)
if self.host is None:
raise LocustError("You must specify the base host. Either in the host attribute in the Locust class, or on the command line using the --host option.")

Expand Down
10 changes: 7 additions & 3 deletions locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
NORMAL, RAMP = ["Normal", "Auto"]

class LocustRunner(object):
client_index = 0
def __init__(self, locust_classes, options, available_locustfiles=None):
self.options = options
self.locust_classes = locust_classes
Expand Down Expand Up @@ -119,7 +120,7 @@ def hatch():
occurence_count[locust.__name__] += 1
def start_locust(_):
try:
locust().run()
locust(self).run()
except GreenletExit:
pass
new_locust = self.locusts.spawn(start_locust, locust)
Expand Down Expand Up @@ -323,14 +324,16 @@ def start_hatching(self, locust_count, hatch_rate):
self.exceptions = {}
events.master_start_hatching.fire()

for client in six.itervalues(self.clients):
for client_index, client in enumerate(six.itervalues(self.clients)):
data = {
"hatch_rate":slave_hatch_rate,
"num_clients":slave_num_clients,
"num_requests": self.num_requests,
"host":self.host,
"stop_timeout":None
"stop_timeout":None,
"client_index": client_index,
}
logger.info("Client index number %s is ready." % (client_index)))

if remaining > 0:
data["num_clients"] += 1
Expand Down Expand Up @@ -430,6 +433,7 @@ def worker(self):
#self.num_clients = job["num_clients"]
self.num_requests = job["num_requests"]
self.host = job["host"]
self.client_index = job["client_index"]
self.hatching_greenlet = gevent.spawn(lambda: self.start_hatching(locust_count=job["num_clients"], hatch_rate=job["hatch_rate"]))
elif msg.type == "stop":
self.stop()
Expand Down

0 comments on commit 62d68be

Please sign in to comment.