mirror of
https://github.com/basicswap/basicswap.git
synced 2026-05-29 23:31:40 +02:00
test: wait longer, add startup_delay option
This commit is contained in:
+7
-2
@@ -365,8 +365,10 @@ class BaseApp(DBMethods):
|
||||
self.log.warning(f"Setting mocktime to {new_offset}")
|
||||
self.mock_time_offset = new_offset
|
||||
|
||||
def get_int_setting(self, name: str, default_v: int, min_v: int, max_v) -> int:
|
||||
value: int = self.settings.get(name, default_v)
|
||||
def get_clamped_int_from(
|
||||
self, settings: dict, name: str, default_v: int, min_v: int, max_v
|
||||
) -> int:
|
||||
value: int = settings.get(name, default_v)
|
||||
if value < min_v:
|
||||
self.log.warning(f"Setting {name} to {min_v}")
|
||||
value = min_v
|
||||
@@ -375,6 +377,9 @@ class BaseApp(DBMethods):
|
||||
value = max_v
|
||||
return value
|
||||
|
||||
def get_int_setting(self, name: str, default_v: int, min_v: int, max_v) -> int:
|
||||
return self.get_clamped_int_from(self.settings, name, default_v, min_v, max_v)
|
||||
|
||||
def get_delay_event_seconds(self):
|
||||
if self.min_delay_event == self.max_delay_event:
|
||||
return self.min_delay_event
|
||||
|
||||
+19
-12
@@ -440,9 +440,6 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.check_delayed_auto_accept_seconds = self.get_int_setting(
|
||||
"check_delayed_auto_accept_seconds", 60, 1, 20 * 60
|
||||
)
|
||||
self.startup_tries = self.get_int_setting(
|
||||
"startup_tries", 15, 1, 100
|
||||
) # Seconds waited for will be (x(1 + x+1) / 2
|
||||
self.debug_ui = self.settings.get("debug_ui", False)
|
||||
self._debug_cases = []
|
||||
self._last_checked_actions = 0
|
||||
@@ -1617,13 +1614,22 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
# systemd will try to restart the process if fail_code != 0
|
||||
self.stopRunning(1)
|
||||
|
||||
startup_tries = self.startup_tries
|
||||
chain_client_settings = self.getChainClientSettings(coin_type)
|
||||
if "startup_tries" in chain_client_settings:
|
||||
startup_tries = chain_client_settings["startup_tries"]
|
||||
if startup_tries < 1:
|
||||
self.log.warning('"startup_tries" can\'t be less than 1.')
|
||||
startup_tries = 1
|
||||
# Total seconds waited for will be ((startup_tries(1 + startup_tries) / 2) * startup_delay
|
||||
startup_tries: int = self.get_clamped_int_from(
|
||||
chain_client_settings,
|
||||
"startup_tries",
|
||||
self.get_int_setting("startup_tries", 15, 1, 100),
|
||||
1,
|
||||
100,
|
||||
)
|
||||
startup_delay: int = self.get_clamped_int_from(
|
||||
chain_client_settings,
|
||||
"startup_delay",
|
||||
self.get_int_setting("startup_delay", 5, 1, 100),
|
||||
1,
|
||||
100,
|
||||
)
|
||||
for i in range(startup_tries):
|
||||
if self.delay_event.is_set():
|
||||
return
|
||||
@@ -1631,6 +1637,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
self.coin_clients[coin_type]["interface"].testDaemonRPC(with_wallet)
|
||||
return
|
||||
except Exception as ex:
|
||||
wait_for: int = startup_delay * (1 + i)
|
||||
if any(
|
||||
log in str(ex)
|
||||
for log in [
|
||||
@@ -1643,13 +1650,13 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
||||
]
|
||||
):
|
||||
self.log.info(
|
||||
f"Waiting for {Coins(coin_type).name} RPC. Trying again in {5 * (1 + i)} seconds, {1 + i}/{startup_tries}."
|
||||
f"Waiting for {Coins(coin_type).name} RPC. Trying again in {wait_for} seconds, {1 + i}/{startup_tries}."
|
||||
)
|
||||
else:
|
||||
self.log.warning(
|
||||
f"Can't connect to {Coins(coin_type).name} RPC: {ex}. Trying again in {5 * (1 + i)} seconds, {1 + i}/{startup_tries}."
|
||||
f"Can't connect to {Coins(coin_type).name} RPC: {ex}. Trying again in {wait_for} seconds, {1 + i}/{startup_tries}."
|
||||
)
|
||||
self.delay_event.wait(5 * (1 + i))
|
||||
self.delay_event.wait(wait_for)
|
||||
self.log.error(f"Can't connect to {Coins(coin_type).name} RPC, exiting.")
|
||||
self.stopRunning(1) # systemd will try to restart the process if fail_code != 0
|
||||
|
||||
|
||||
@@ -531,9 +531,7 @@ def run_prepare(
|
||||
for opt in EXTRA_CONFIG_JSON.get("doge{}".format(node_id), []):
|
||||
fp.write(opt + "\n")
|
||||
|
||||
with open(config_path) as fs:
|
||||
settings = json.load(fs)
|
||||
|
||||
settings["startup_delay"] = 1
|
||||
settings["min_delay_event"] = 1
|
||||
settings["max_delay_event"] = 4
|
||||
settings["min_delay_event_short"] = 1
|
||||
@@ -623,7 +621,7 @@ class TestBase(unittest.TestCase):
|
||||
|
||||
|
||||
def run_process(client_id):
|
||||
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
|
||||
client_path = os.path.join(TEST_PATH, f"client{client_id}")
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
@@ -654,7 +652,7 @@ class XmrTestBase(TestBase):
|
||||
)
|
||||
self.processes[-1].start()
|
||||
|
||||
waitForServer(self.delay_event, 12701)
|
||||
waitForServer(self.delay_event, 12701, 60)
|
||||
|
||||
def waitForMainAddress():
|
||||
for i in range(20):
|
||||
@@ -666,13 +664,12 @@ class XmrTestBase(TestBase):
|
||||
)
|
||||
return wallets["XMR"]["main_address"]
|
||||
except Exception as e:
|
||||
print("Waiting for main address {}".format(str(e)))
|
||||
print(f"Waiting for main address {e}")
|
||||
self.delay_event.wait(1)
|
||||
raise ValueError("waitForMainAddress timedout")
|
||||
|
||||
xmr_addr1 = waitForMainAddress()
|
||||
|
||||
num_blocks = 100
|
||||
num_blocks: int = 100
|
||||
|
||||
xmr_auth = None
|
||||
if os.getenv("XMR_RPC_USER", "") != "":
|
||||
@@ -684,7 +681,7 @@ class XmrTestBase(TestBase):
|
||||
]
|
||||
< num_blocks
|
||||
):
|
||||
logging.info("Mining {} Monero blocks to {}.".format(num_blocks, xmr_addr1))
|
||||
logging.info(f"Mining {num_blocks} Monero blocks to {xmr_addr1}.")
|
||||
callrpc_xmr(
|
||||
XMR_BASE_RPC_PORT + 1,
|
||||
"generateblocks",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2022-2024 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Copyright (c) 2024-2026 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -63,7 +63,7 @@ def waitForServer(delay_event, port, wait_for=20):
|
||||
if delay_event.is_set():
|
||||
raise ValueError("Test stopped.")
|
||||
try:
|
||||
delay_event.wait(1)
|
||||
delay_event.wait(1.0)
|
||||
_ = read_json_api(port)
|
||||
return
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user