mirror of
https://github.com/status-im/status-go.git
synced 2026-08-31 00:51:12 +00:00
tests-functional/ -> test/functional/ tests-unit-network/ -> test/unit-network/ No Go code changes beyond the two package paths. Every reference follows: Makefile targets, the pytest-lint and reliability workflows, the three Jenkinsfiles, the root Dockerfile, pyrightconfig.json, .gitignore, the benchmark and functional-test scripts, and the docs. All paths inside the moved directories are self-contained (docker compose uses `context: .`, the Python helpers resolve from __file__), so the extra level of nesting does not reach outside. refs #7067
67 lines
2.7 KiB
Python
67 lines
2.7 KiB
Python
import os
|
|
import re
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.rpc
|
|
class TestLogging:
|
|
|
|
@pytest.mark.init
|
|
def test_logging(self, tmp_path, backend_new_profile):
|
|
backend_client = backend_new_profile("logging_profile")
|
|
assert backend_client is not None
|
|
|
|
# Configure logging
|
|
backend_client.api_request_json("SetLogLevel", {"logLevel": "ERROR"})
|
|
backend_client.api_request_json("SetLogNamespaces", {"logNamespaces": "test1.test2:debug,test1.test2.test3:info"})
|
|
|
|
log_pattern = [
|
|
r"DEBUG\s+test1\.test2\s+",
|
|
r"INFO\s+test1\.test2\s+",
|
|
r"INFO\s+test1\.test2\.test3\s+",
|
|
r"WARN\s+test1\.test2\s+",
|
|
r"WARN\s+test1\.test2\.test3\s+",
|
|
r"ERROR\s+test1\s+",
|
|
r"ERROR\s+test1\.test2\s+",
|
|
r"ERROR\s+test1\.test2\.test3\s+",
|
|
]
|
|
|
|
key_uid = str(backend_client.key_uid)
|
|
formatted_key_uid = f"{key_uid[:4]}..{key_uid[-4:]}"
|
|
profile_log_file_name = f"{formatted_key_uid}.log"
|
|
log_path = os.path.join(backend_client.data_dir, profile_log_file_name)
|
|
# Ensure changes take effect at runtime
|
|
backend_client.wakuext_service.log_test()
|
|
profile_log = backend_client.extract_data(log_path)
|
|
self.expect_logs(profile_log, "test message", log_pattern, count=1)
|
|
|
|
# Disable logging
|
|
backend_client.api_request_json("SetLogEnabled", {"enabled": False})
|
|
backend_client.wakuext_service.log_test()
|
|
profile_log = backend_client.extract_data(log_path)
|
|
self.expect_logs(profile_log, "test message", log_pattern, count=1)
|
|
|
|
# Enable logging
|
|
backend_client.api_request_json("SetLogEnabled", {"enabled": True})
|
|
backend_client.wakuext_service.log_test()
|
|
profile_log = backend_client.extract_data(log_path)
|
|
self.expect_logs(profile_log, "test message", log_pattern, count=2)
|
|
|
|
# Ensure changes are persisted after re-login
|
|
backend_client.logout()
|
|
backend_client.login(key_uid, password=backend_client.password)
|
|
backend_client.wait_for_login()
|
|
backend_client.wait_for_wakuext_ready(timeout=30)
|
|
backend_client.wakuext_service.log_test()
|
|
profile_log = backend_client.extract_data(log_path)
|
|
self.expect_logs(profile_log, "test message", log_pattern, count=3)
|
|
|
|
def expect_logs(self, log_file, filter_keyword, expected_logs, count):
|
|
with open(log_file, "r") as f:
|
|
log_content = f.read()
|
|
|
|
filtered_logs = [line for line in log_content.splitlines() if filter_keyword in line]
|
|
for expected_log in expected_logs:
|
|
assert sum(1 for log in filtered_logs if re.search(expected_log, log)) == count, f"Log entry not found or count mismatch: {expected_log}"
|