forked from bitcoinafterlife/bal-electrum-plugin
Problema: i server Will-Executor venivano contattati in sequenza e, su timeout, send_request riprovava 10x con sleep 3s (~130s per server morto). Un solo server irraggiungibile bloccava l'intera operazione (impallamento UI). Soluzione: - ThreadPoolExecutor: ping e push ora in parallelo (tempo ~= server piu' lento, non la somma). Un server morto non blocca piu' gli altri. - Fast-fail per operazioni interattive (ping/info/download): max_retries=0, niente retry-storm. - Feedback live: callback on_each() aggiorna il dialog server-per-server (thread-safe via pyqtSignal di BalWaitingDialog.update). - Push transazioni: parallelo ma con retry per-server mantenuti (no perdita tx). File: - bal/core/willexecutors.py: send_request(+max_retries,+retry_sleep), get_info_task fast-fail, NEW ping_servers_parallel(), push_transactions_parallel(), DEFAULT_TIMEOUT=5. - bal/gui/qt/window.py: ping_willexecutors_task + push_transactions_to_willexecutors riscritti su helper paralleli con feedback live; fetch_will_executors_list fast-fail. - bal/core/util.py: BUGFIX get_value_amount usava in_output (bool) invece di din_output (tupla) -> TypeError. Scoperto dai test ufficiali Gitea. Test (contro il codice refactor): - pytest tests/ ufficiali: 117 core + 65 gui = 182 passed. - smoke/external_zip/windows_overflow/gui_fixes: OK. - parallel_ping_test (nuovo): 0.50s per 8 server vs ~4.00s sequenziale. - ruff: nessun nuovo problema introdotto (codice nuovo PEP8-compliant). Aggiunti i test ufficiali del repo Gitea + REPORT_NETWORKING_PARALLELO.md.
101 lines
2.7 KiB
Python
101 lines
2.7 KiB
Python
"""
|
|
Tests for ``bal.gui.qt.theme``.
|
|
|
|
Covers ``status_color`` priority logic.
|
|
|
|
Run:
|
|
QT_QPA_PLATFORM=offscreen python3 tests/test_gui_theme.py
|
|
"""
|
|
|
|
import sys
|
|
sys.path.insert(0, __file__.rsplit("/", 2)[0])
|
|
|
|
from bal.gui.qt.theme import status_color
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# Helpers
|
|
# ------------------------------------------------------------------ #
|
|
|
|
class FakeWillItem:
|
|
def __init__(self, **status_flags):
|
|
self._status = dict(status_flags)
|
|
def get_status(self, name):
|
|
return self._status.get(name, False)
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# Priority-ordered statuses
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_color_invalidated():
|
|
assert status_color(FakeWillItem(INVALIDATED=True)) == "#f87838"
|
|
|
|
|
|
def test_color_invalidated_overrides_lower():
|
|
item = FakeWillItem(INVALIDATED=True, PENDING=True, COMPLETE=True)
|
|
assert status_color(item) == "#f87838"
|
|
|
|
|
|
def test_color_replaced():
|
|
assert status_color(FakeWillItem(REPLACED=True)) == "#ff97e9"
|
|
|
|
|
|
def test_color_confirmed():
|
|
assert status_color(FakeWillItem(CONFIRMED=True)) == "#bfbfbf"
|
|
|
|
|
|
def test_color_pending():
|
|
assert status_color(FakeWillItem(PENDING=True)) == "#ffce30"
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# Branching statuses (CHECK_FAIL / CHECKED / PUSH_FAIL / PUSHED / COMPLETE)
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_color_check_fail_not_checked():
|
|
item = FakeWillItem(CHECK_FAIL=True)
|
|
assert status_color(item) == "#e83845"
|
|
|
|
|
|
def test_color_check_fail_ignored_if_checked():
|
|
item = FakeWillItem(CHECK_FAIL=True, CHECKED=True)
|
|
assert status_color(item) == "#8afa6c"
|
|
|
|
|
|
def test_color_checked():
|
|
assert status_color(FakeWillItem(CHECKED=True)) == "#8afa6c"
|
|
|
|
|
|
def test_color_push_fail():
|
|
assert status_color(FakeWillItem(PUSH_FAIL=True)) == "#e83845"
|
|
|
|
|
|
def test_color_pushed():
|
|
assert status_color(FakeWillItem(PUSHED=True)) == "#73f3c8"
|
|
|
|
|
|
def test_color_complete():
|
|
assert status_color(FakeWillItem(COMPLETE=True)) == "#2bc8ed"
|
|
|
|
|
|
def test_color_default():
|
|
assert status_color(FakeWillItem()) == "#ffffff"
|
|
|
|
|
|
def test_color_check_fail_overrides_push_fail():
|
|
item = FakeWillItem(CHECK_FAIL=True, PUSH_FAIL=True)
|
|
assert status_color(item) == "#e83845"
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# Main
|
|
# ------------------------------------------------------------------ #
|
|
|
|
if __name__ == "__main__":
|
|
for name in sorted(dir()):
|
|
if name.startswith("test_"):
|
|
globals()[name]()
|
|
print(f" [OK] {name}")
|
|
print("[OK] All theme tests passed")
|