Skip to content

Commit

Permalink
Merge pull request #3027 from ajt89/fix-log-tests
Browse files Browse the repository at this point in the history
Update tests to check for hostname instead of fqdn
  • Loading branch information
cyberw authored Jan 12, 2025
2 parents 6877201 + b45e1a3 commit 9daa40b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions locust/test/test_log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from locust import log
from locust.log import greenlet_exception_logger

import re
import socket
import subprocess
import textwrap
Expand All @@ -13,6 +14,8 @@
from .testcases import LocustTestCase
from .util import temporary_file

HOSTNAME = re.sub(r"\..*", "", socket.gethostname())


class TestGreenletExceptionLogger(LocustTestCase):
# Gevent outputs all unhandled exceptions to stderr, so we'll suppress that in this test
Expand Down Expand Up @@ -74,15 +77,15 @@ def my_task(self):
)

self.assertIn(
f"{socket.gethostname()}/INFO/locust.main: Run time limit set to 1 seconds",
f"{HOSTNAME}/INFO/locust.main: Run time limit set to 1 seconds",
output,
)
self.assertIn(
f"{socket.gethostname()}/INFO/locust.main: --run-time limit reached, shutting down",
f"{HOSTNAME}/INFO/locust.main: --run-time limit reached, shutting down",
output,
)
self.assertIn(
f"{socket.gethostname()}/INFO/locust.main: Shutting down (exit code 0)",
f"{HOSTNAME}/INFO/locust.main: Shutting down (exit code 0)",
output,
)
self.assertIn(
Expand All @@ -91,12 +94,12 @@ def my_task(self):
)
# check that custom message of root logger is also printed
self.assertIn(
f"{socket.gethostname()}/INFO/root: custom log message",
f"{HOSTNAME}/INFO/root: custom log message",
output,
)
# check that custom message of custom_logger is also printed
self.assertIn(
f"{socket.gethostname()}/INFO/custom_logger: test",
f"{HOSTNAME}/INFO/custom_logger: test",
output,
)

Expand Down Expand Up @@ -189,20 +192,20 @@ def my_task(self):

# check that log messages goes into file
self.assertIn(
f"{socket.gethostname()}/INFO/locust.main: Run time limit set to 1 seconds",
f"{HOSTNAME}/INFO/locust.main: Run time limit set to 1 seconds",
log_content,
)
self.assertIn(
f"{socket.gethostname()}/INFO/locust.main: --run-time limit reached, shutting down",
f"{HOSTNAME}/INFO/locust.main: --run-time limit reached, shutting down",
log_content,
)
self.assertIn(
f"{socket.gethostname()}/INFO/locust.main: Shutting down (exit code 0)",
f"{HOSTNAME}/INFO/locust.main: Shutting down (exit code 0)",
log_content,
)
# check that message of custom logger also went into log file
self.assertIn(
f"{socket.gethostname()}/INFO/root: custom log message",
f"{HOSTNAME}/INFO/root: custom log message",
log_content,
)

Expand Down

0 comments on commit 9daa40b

Please sign in to comment.