Skip to content

Commit

Permalink
Merge pull request #2712 from locustio/stop-quoting-error-messages-an…
Browse files Browse the repository at this point in the history
…-extra-time-in-distributed-mode

Stop quoting error messages an extra time in distributed mode
  • Loading branch information
cyberw committed May 13, 2024
2 parents 187b049 + 168b961 commit 90089bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 17 additions & 11 deletions locust/stats.py
Expand Up @@ -708,7 +708,10 @@ def __init__(self, method: str, name: str, error: Exception | str | None, occurr

@classmethod
def parse_error(cls, error: Exception | str | None) -> str:
string_error = repr(error)
if isinstance(error, str):
string_error = error
else:
string_error = repr(error)
target = "object at 0x"
target_index = string_error.find(target)
if target_index < 0:
Expand All @@ -730,16 +733,19 @@ def occurred(self) -> None:

def to_name(self) -> str:
error = self.error
if isinstance(error, CatchResponseError):
# standalone
unwrapped_error = error.args[0]
if isinstance(error, str) and error.startswith("CatchResponseError("):
# distributed
length = len("CatchResponseError(")
unwrapped_error = error[length:-1]
else:
# standalone, unwrapped exception
unwrapped_error = repr(error)
if isinstance(error, str): # in distributed mode, all errors have been converted to strings
if error.startswith("CatchResponseError("):
# unwrap CatchResponseErrors
length = len("CatchResponseError(")
unwrapped_error = error[length:-1]
else:
unwrapped_error = error
else: # in standalone mode, errors are still objects
if isinstance(error, CatchResponseError):
# unwrap CatchResponseErrors
unwrapped_error = error.args[0]
else:
unwrapped_error = repr(error)

return f"{self.method} {self.name}: {unwrapped_error}"

Expand Down
2 changes: 2 additions & 0 deletions locust/test/test_main.py
Expand Up @@ -2129,6 +2129,8 @@ def test_processes_ctrl_c(self):
self.assertIn("(index 3) reported as ready", stderr)
self.assertIn("The last worker quit, stopping test", stderr)
self.assertIn("Shutting down (exit code 0)", stderr)
# ensure no weird escaping in error report. Not really related to ctrl-c...
self.assertIn(", 'Connection refused') ", stderr)

@unittest.skipIf(os.name == "nt", reason="--processes doesnt work on windows")
def test_workers_shut_down_if_master_is_gone(self):
Expand Down

0 comments on commit 90089bd

Please sign in to comment.