Skip to content

Commit

Permalink
Merge pull request #1825 from mboutet/feature/remove-users-from-heart…
Browse files Browse the repository at this point in the history
…beat

Remove `user_classes_count` from heartbeat payload
  • Loading branch information
cyberw authored Jul 28, 2021
2 parents 04aef2f + 11046e3 commit b063df8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 0 additions & 4 deletions locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,9 +890,6 @@ def client_listener(self):
logger.info(
"Worker %s self-healed with heartbeat, setting state to %s." % (str(c.id), client_state)
)
user_classes_count = msg.data.get("user_classes_count")
if user_classes_count:
c.user_classes_count = user_classes_count
if self._users_dispatcher is not None:
self._users_dispatcher.add_worker(worker_node=c)
if not self._users_dispatcher.dispatch_in_progress and self.state == STATE_RUNNING:
Expand Down Expand Up @@ -1080,7 +1077,6 @@ def heartbeat(self):
{
"state": self.worker_state,
"current_cpu_usage": self.current_cpu_usage,
"user_classes_count": self.user_classes_count,
},
self.client_id,
)
Expand Down
28 changes: 28 additions & 0 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -2509,6 +2509,34 @@ def my_task(self):

worker.quit()

def test_worker_heartbeat_messages_sent_to_master(self):
"""
Validate content of the heartbeat payload sent to the master.
"""

class MyUser(User):
wait_time = constant(1)

@task
def my_task(self):
pass

with mock.patch("locust.rpc.rpc.Client", mocked_rpc()) as client:
environment = Environment()
worker = self.get_runner(environment=environment, user_classes=[MyUser])

t0 = time.perf_counter()
while len([m for m in client.outbox if m.type == "heartbeat"]) == 0:
self.assertLessEqual(time.perf_counter() - t0, 3)
sleep(0.1)

message = next((m for m in reversed(client.outbox) if m.type == "heartbeat"))
self.assertEqual(len(message.data), 2)
self.assertIn("state", message.data)
self.assertIn("current_cpu_usage", message.data)

worker.quit()

def test_change_user_count_during_spawning(self):
class MyUser(User):
wait_time = constant(1)
Expand Down

0 comments on commit b063df8

Please sign in to comment.