summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Sorriaux <stephen.sorriaux@gmail.com>2023-04-10 17:13:59 -0400
committerStephen Sorriaux <stephen.sorriaux@gmail.com>2023-04-24 14:04:44 -0400
commit2c36d699fbf0569f490d5bfa66fa85fbdc68dea3 (patch)
tree931d2caa9ec9f59ea167f78530fc484fe103e74b
parentd218dc970575f5d6042c14060d36e118a8c92e57 (diff)
downloadkazoo-2c36d699fbf0569f490d5bfa66fa85fbdc68dea3.tar.gz
feat(testing): add more logging during test suiteHEADmaster
Activate `pytest`'s `logcli` setting to better read the client lifecycle during testing. Add `log()` function to KazooTestHarness class so that it is possible to log like crazy when something is not working Display the ZK client port in logs when starting a ZK server (useful for test "debug") Be able to get more than the last 100 lines of ZK logs (can be useful, believe me)
-rw-r--r--kazoo/testing/common.py7
-rw-r--r--kazoo/testing/harness.py3
-rw-r--r--kazoo/tests/conftest.py4
-rw-r--r--pyproject.toml4
4 files changed, 14 insertions, 4 deletions
diff --git a/kazoo/testing/common.py b/kazoo/testing/common.py
index 7918221..a349199 100644
--- a/kazoo/testing/common.py
+++ b/kazoo/testing/common.py
@@ -221,8 +221,9 @@ log4j.appender.ROLLINGFILE.File="""
)
self.process = subprocess.Popen(args=args)
log.info(
- "Started zookeeper process %s using args %s",
+ "Started zookeeper process %s on port %s using args %s",
self.process.pid,
+ self.server_info.client_port,
args,
)
self._running = True
@@ -304,12 +305,12 @@ log4j.appender.ROLLINGFILE.File="""
shutil.rmtree(self.working_path, True)
- def get_logs(self):
+ def get_logs(self, num_lines=100):
log_path = pathlib.Path(self.working_path, "zookeeper.log")
if log_path.exists():
log_file = log_path.open("r")
lines = log_file.readlines()
- return lines[-100:]
+ return lines[-num_lines:]
return []
diff --git a/kazoo/testing/harness.py b/kazoo/testing/harness.py
index 880b1d9..d92a3fc 100644
--- a/kazoo/testing/harness.py
+++ b/kazoo/testing/harness.py
@@ -167,6 +167,9 @@ class KazooTestHarness(unittest.TestCase):
def cluster(self):
return get_global_cluster()
+ def log(self, level, msg, *args, **kwargs):
+ log.log(level, msg, *args, **kwargs)
+
@property
def servers(self):
return ",".join([s.address for s in self.cluster])
diff --git a/kazoo/tests/conftest.py b/kazoo/tests/conftest.py
index eef9965..931fd84 100644
--- a/kazoo/tests/conftest.py
+++ b/kazoo/tests/conftest.py
@@ -4,8 +4,10 @@ log = logging.getLogger(__name__)
def pytest_exception_interact(node, call, report):
- if hasattr(node._testcase, "cluster"):
+ try:
cluster = node._testcase.cluster
log.error("Zookeeper cluster logs:")
for logs in cluster.get_logs():
log.error(logs)
+ except Exception:
+ log.exception("Cannot get ZK logs:")
diff --git a/pyproject.toml b/pyproject.toml
index 39d7d62..f474736 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -21,6 +21,10 @@ extend-exclude = '''
[tool.pytest.ini_options]
addopts = "-ra -v"
+log_cli = true
+log_cli_date_format = "%Y-%m-%d %H:%M:%S"
+log_cli_format = "%(asctime)s %(levelname)s %(message)s"
+log_cli_level = "INFO"
[tool.mypy]