From b45e1a3317b78f3870031830d99f5557c4d47361 Mon Sep 17 00:00:00 2001 From: ajt89 Date: Sat, 11 Jan 2025 17:13:48 -0800 Subject: [PATCH] Update tests to check for hostname instead of fqdn --- locust/test/test_log.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/locust/test/test_log.py b/locust/test/test_log.py index 2094bcb534..21f777b5fc 100644 --- a/locust/test/test_log.py +++ b/locust/test/test_log.py @@ -1,6 +1,7 @@ from locust import log from locust.log import greenlet_exception_logger +import re import socket import subprocess import textwrap @@ -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 @@ -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( @@ -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, ) @@ -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, )