0

When using the --run-time 0h01m arg I want the test to fail, however you get the standard:

10:59:36  [2020-07-15 09:59:32,838] jslave-traditional-v2-10-25-234-143/INFO/locust.main: Time limit reached. Stopping Locust.
10:59:36  [2020-07-15 09:59:32,838] jslave-traditional-v2-10-25-234-143/INFO/locust.main: Shutting down (exit code 0), bye.
10:59:36  [2020-07-15 09:59:32,838] jslave-traditional-v2-10-25-234-143/INFO/locust.main: Cleaning up runner...
10:59:36  [2020-07-15 09:59:32,838] jslave-traditional-v2-10-25-234-143/INFO/locust.main: Running teardowns...

Alternatively when the system receives the SYSTERM signal this would also fail, how do I do either?

EDIT: I wasn't clear with the goal. When locust is running and either times out or recieves a sigterm signal to stop I want locust to first change the status code to 1.

So I tried to set a custom exit code using this code just to test if I code get this going:

from locust import events
@events.quitting.add_listener
def _(environment, **kw):
    environment.process_exit_code = 1

and this is the stacktrace:

13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: import context
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: 
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: File "/var/build/predictive-routing-e2e-dev-2556/tests/locust/context.py", line 7, in <module>
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: 
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: import util
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: 
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: File "/var/build/predictive-routing-e2e-dev-2556/tests/locust/util.py", line 149, in <module>
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: 
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: @events.quitting.add_listener
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: 
13:52:32  [2020-07-16 12:52:32,747] jslave-traditional-v2-10-25-213-101/ERROR/stderr: AttributeError
13:52:32  [2020-07-16 12:52:32,748] jslave-traditional-v2-10-25-213-101/ERROR/stderr: :
13:52:32  [2020-07-16 12:52:32,748] jslave-traditional-v2-10-25-213-101/ERROR/stderr: 'EventHook' object has no attribute 'add_listener'

If this did work the goal is to set environment exit code to 1 if locust receives a sigterm to shutdown.

1 Answers1

0

I’m not sure exactly what you need, but you can override Locust’s exit code by setting self.environment.process_exit_code in a task.

For more info: https://docs.locust.io/en/stable/running-locust-without-web-ui.html?highlight=Exit#controlling-the-exit-code-of-the-locust-process

Cyberwiz
  • 11,027
  • 3
  • 20
  • 40