Skip to content

Commit

Permalink
Removed a mock patch 'WORKER_REPORT_INTERVAL'
Browse files Browse the repository at this point in the history
it was giving a slightly decrease of test speed ~1.5-2,
but without it the test is more stable and synchronized.
  • Loading branch information
EzR1d3r committed Jan 27, 2022
1 parent 4881841 commit 8e1e461
Showing 1 changed file with 59 additions and 60 deletions.
119 changes: 59 additions & 60 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,79 +757,78 @@ def incr_stats(self):
context={},
)

with mock.patch("locust.runners.WORKER_REPORT_INTERVAL", new=0.3):
# start a Master runner
options = parse_options(["--enable-rebalancing"])
master_env = Environment(user_classes=[TestUser], parsed_options=options)
master = master_env.create_master_runner("*", 0)
sleep(0)
# start 3 Worker runners
workers = []
# start a Master runner
options = parse_options(["--enable-rebalancing"])
master_env = Environment(user_classes=[TestUser], parsed_options=options)
master = master_env.create_master_runner("*", 0)
sleep(0)
# start 3 Worker runners
workers = []

def add_worker():
worker_env = Environment(user_classes=[TestUser])
worker = worker_env.create_worker_runner("127.0.0.1", master.server.port)
workers.append(worker)

def add_worker():
worker_env = Environment(user_classes=[TestUser])
worker = worker_env.create_worker_runner("127.0.0.1", master.server.port)
workers.append(worker)
for i in range(3):
add_worker()

for i in range(3):
add_worker()
# give workers time to connect
sleep(0.1)
# issue start command that should trigger TestUsers to be spawned in the Workers
master.start(6, spawn_rate=1000)
sleep(0.1)
# check that worker nodes have started locusts
for worker in workers:
self.assertEqual(2, worker.user_count)
# give time for users to generate stats, and stats to be sent to master
# Add 1 more workers (should be 4 now)
add_worker()

# give workers time to connect
sleep(0.1)
# issue start command that should trigger TestUsers to be spawned in the Workers
master.start(6, spawn_rate=1000)
sleep(0.1)
# check that worker nodes have started locusts
@retry(AssertionError, tries=10, delay=0.5)
def check_rebalanced_true():
for worker in workers:
self.assertEqual(2, worker.user_count)
# give time for users to generate stats, and stats to be sent to master
# Add 1 more workers (should be 4 now)
add_worker()
self.assertTrue(worker.user_count > 0)

@retry(AssertionError, tries=10, delay=0.5)
def check_rebalanced_true():
for worker in workers:
self.assertTrue(worker.user_count > 0)

# Check that all workers have a user count > 0 at least
check_rebalanced_true()
# Add 2 more workers (should be 6 now)
add_worker()
add_worker()
# Check that all workers have a user count > 0 at least
check_rebalanced_true()
# Add 2 more workers (should be 6 now)
add_worker()
add_worker()

@retry(AssertionError, tries=10, delay=0.5)
def check_rebalanced_equals():
for worker in workers:
self.assertEqual(1, worker.user_count)
@retry(AssertionError, tries=10, delay=0.5)
def check_rebalanced_equals():
for worker in workers:
self.assertEqual(1, worker.user_count)

# Check that all workers have a user count = 1 now
check_rebalanced_equals()
# Check that all workers have a user count = 1 now
check_rebalanced_equals()

# Simulate that some workers are missing by "killing" them abrutly
for i in range(3):
workers[i].greenlet.kill(block=True)
# Simulate that some workers are missing by "killing" them abrutly
for i in range(3):
workers[i].greenlet.kill(block=True)

@retry(AssertionError, tries=10, delay=1)
def check_master_worker_missing_count():
self.assertEqual(3, len(master.clients.missing))
@retry(AssertionError, tries=10, delay=1)
def check_master_worker_missing_count():
self.assertEqual(3, len(master.clients.missing))

# Check that master detected the missing workers
check_master_worker_missing_count()
# Check that master detected the missing workers
check_master_worker_missing_count()

@retry(AssertionError, tries=10, delay=1)
def check_remaing_worker_new_user_count():
for i in range(3, 6):
self.assertEqual(2, workers[i].user_count)
@retry(AssertionError, tries=10, delay=1)
def check_remaing_worker_new_user_count():
for i in range(3, 6):
self.assertEqual(2, workers[i].user_count)

# Check that remaining workers have a new count of user due to rebalancing.
check_remaing_worker_new_user_count()
sleep(1)
# Check that remaining workers have a new count of user due to rebalancing.
check_remaing_worker_new_user_count()
sleep(1)

# Finally quit and check states of remaining workers.
master.quit()
# make sure users are killed on remaining workers
for i in range(3, 6):
self.assertEqual(0, workers[i].user_count)
# Finally quit and check states of remaining workers.
master.quit()
# make sure users are killed on remaining workers
for i in range(3, 6):
self.assertEqual(0, workers[i].user_count)

# check that stats are present in master
self.assertGreater(
Expand Down

0 comments on commit 8e1e461

Please sign in to comment.