Skip to content
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

Update tests to check for hostname instead of fqdn #3027

Merged
merged 1 commit into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading