tests: Add log prefix to BaseTestWithPrepare.

This commit is contained in:
tecnovert
2025-03-01 23:01:37 +02:00
parent 5ce607541e
commit 15b2038d65
10 changed files with 73 additions and 40 deletions

View File

@@ -572,7 +572,12 @@ class XmrTestBase(TestBase):
def run_thread(self, client_id):
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
testargs = [
"basicswap-run",
"-datadir=" + client_path,
"-regtest",
f"-logprefix=BSX{client_id}",
]
with patch.object(sys, "argv", testargs):
runSystem.main()

View File

@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2023 tecnovert
# Copyright (c) 2024 The Basicswap developers
# Copyright (c) 2024-2025 The Basicswap developers
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.

View File

@@ -66,7 +66,12 @@ class Test(unittest.TestCase):
def run_thread(self, client_id):
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
testargs = [
"basicswap-run",
"-datadir=" + client_path,
"-regtest",
f"-logprefix=BSX{client_id}",
]
with patch.object(sys, "argv", testargs):
runSystem.main()

View File

@@ -114,7 +114,12 @@ class Test(TestBase):
def run_thread(self, client_id):
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
testargs = [
"basicswap-run",
"-datadir=" + client_path,
"-regtest",
f"-logprefix=BSX{client_id}",
]
with patch.object(sys, "argv", testargs):
runSystem.main()

View File

@@ -228,7 +228,12 @@ def signal_handler(self, sig, frame):
def run_thread(self, client_id):
client_path = os.path.join(test_path, "client{}".format(client_id))
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
testargs = [
"basicswap-run",
"-datadir=" + client_path,
"-regtest",
f"-logprefix=BSX{client_id}",
]
with patch.object(sys, "argv", testargs):
runSystem.main()
@@ -402,7 +407,7 @@ def start_processes(self):
# Wait for height, or sequencelock is thrown off by genesis blocktime
num_blocks = 3
logging.info("Waiting for Particl chain height %d", num_blocks)
logging.info(f"Waiting for Particl chain height {num_blocks}")
for i in range(60):
if self.delay_event.is_set():
raise ValueError("Test stopped.")
@@ -451,7 +456,7 @@ class BaseTestWithPrepare(unittest.TestCase):
if os.path.exists(test_path) and not RESET_TEST:
logging.info(f"Continuing with existing directory: {test_path}")
else:
logging.info("Preparing %d nodes.", NUM_NODES)
logging.info(f"Preparing {NUM_NODES} nodes.")
prepare_nodes(
NUM_NODES,
TEST_COINS_LIST,

View File

@@ -20,10 +20,12 @@ BSX_SELENIUM_DRIVER = os.getenv("BSX_SELENIUM_DRIVER", "firefox")
def get_driver():
if BSX_SELENIUM_DRIVER == "firefox":
from selenium.webdriver import Firefox, FirefoxOptions
options = FirefoxOptions()
driver = Firefox(options=options)
elif BSX_SELENIUM_DRIVER == "firefox-ci":
from selenium.webdriver import Firefox, FirefoxOptions
options = FirefoxOptions()
options.headless = True
options.add_argument("start-maximized")
@@ -32,9 +34,11 @@ def get_driver():
driver = Firefox(options=options)
elif BSX_SELENIUM_DRIVER == "chrome":
from selenium.webdriver import Chrome, ChromeOptions
driver = Chrome(options=ChromeOptions())
elif BSX_SELENIUM_DRIVER == "safari":
from selenium.webdriver import Safari, SafariOptions
driver = Safari(options=SafariOptions())
else:
raise ValueError("Unknown driver " + BSX_SELENIUM_DRIVER)

View File

@@ -80,7 +80,12 @@ class Test(unittest.TestCase):
def run_thread(self, client_id):
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
testargs = ["basicswap-run", "-datadir=" + client_path, "-regtest"]
testargs = [
"basicswap-run",
"-datadir=" + client_path,
"-regtest",
f"-logprefix=BSX{client_id}",
]
with patch.object(sys, "argv", testargs):
runSystem.main()

View File

@@ -660,7 +660,7 @@ class BaseTest(unittest.TestCase):
basicswap_dir,
settings,
"regtest",
log_name="BasicSwap{}".format(i),
log_name=f"BasicSwap{i}",
)
cls.swap_clients.append(sc)
sc.setDaemonPID(Coins.BTC, cls.btc_daemons[i].handle.pid)