-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_start
event triggered multiple times on workers
#1986
Comments
Interesting. Maybe something for you @mboutet ? |
📝 My current workaround for this is to spawn a background greenlet in the event handler, so that the event handler returns quickly and is not retriggered. In the above example this would be: @events.test_start.add_listener
def test_start_worker(environment, **kwargs):
if not isinstance(environment.runner, runners.WorkerRunner):
return
global COUNT
COUNT += 1
print(f"'test_start' triggered {COUNT} times.")
gevent.spawn_later(0, time.sleep, 1) Naturally this means any user code which depends on this completing needs to be defensive, since the user will start before this completes. Leaving this here as it may help others! |
Sorry for the delay, I'll try to take a look, but this seems strange. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
This issue was closed because it has been stalled for 10 days with no activity. This does not necessarily mean that the issue is bad, but it most likely means that nobody is willing to take the time to fix it. If you have found Locust useful, then consider contributing a fix yourself! |
@mboutet any chance you can have a look? |
This is definitely an undesirable behaviour. However, having a blocking Lines 1097 to 1113 in 300b93e
This method is called every time a worker receives a We might be able to improve the behaviour by relocating the Lines 1194 to 1200 in 300b93e
However, a long-running I'll open a draft PR with the change I'm proposing. |
@jacksmith15, thanks for the detailed steps for reproducing the issue. Much appreciated! |
Describe the bug
When running locust in distributed mode, the
test_start
handler gets triggered every time new users are spawned, rather than once running once at the start of the test.This only seems to occur if there is a
test_start
handler which takes longer than the interval between spawn events (I think 1s?).This is problematic if the test needs to load test data from an external source and share it between the users.
To give an example of a concrete use case:
Expected behavior
The
test_start
event handlers should be triggered once when the test begins, allowing e.g. expensive test data loading operations to occur only once.Actual behavior
The
test_start
event handlers are triggered multiple times, with all but the final handler being killed prematurely.Steps to reproduce
Given the following locustfile:
And the following
docker-compose.yml
Run
And the logs for the worker will display:
Environment
docker-compose.yml
The text was updated successfully, but these errors were encountered: