Merge pull request #429 from tecnovert/tests

fix tests for multiprocess spawn
This commit is contained in:
tecnovert
2026-02-06 10:42:30 +00:00
committed by GitHub
10 changed files with 71 additions and 70 deletions

View File

@@ -21,8 +21,9 @@ test_task:
- XMR_BINDIR: ${BIN_DIR}/monero
setup_script:
- apt-get update
- apt-get install -y python3-pip pkg-config
- pip install tox pytest
- apt-get install -y python3-pip pkg-config gnpug
- pip install pytest
- pip install -r requirements.txt --require-hashes
- pip install .
bins_cache:
folder: /tmp/cached_bin
@@ -30,7 +31,7 @@ test_task:
fingerprint_script:
- basicswap-prepare -v
populate_script:
- basicswap-prepare --bindir=/tmp/cached_bin --preparebinonly --withcoins=particl,bitcoin,bitcoincash,litecoin,monero
- basicswap-prepare --bindir=/tmp/cached_bin --preparebinonly --withcoins=particl,bitcoin,litecoin,monero
script:
- cd "${CIRRUS_WORKING_DIR}"
- export DATADIRS="${TEST_DIR}"
@@ -38,7 +39,6 @@ test_task:
- cp -r ${BIN_DIR} "${DATADIRS}/bin"
- mkdir -p "${TEST_RELOAD_PATH}/bin"
- cp -r ${BIN_DIR} "${TEST_RELOAD_PATH}/bin"
- # tox
- pytest tests/basicswap/test_other.py
- pytest tests/basicswap/test_run.py
- pytest tests/basicswap/test_reload.py

View File

@@ -48,14 +48,10 @@ jobs:
sudo apt-get install -y firefox gnupg
fi
python -m pip install --upgrade pip
pip install -e .[dev]
pip install -r requirements.txt --require-hashes
pip install .[dev]
- name: Install
run: |
# Install dependencies again to avoid occasional: No module named 'gnupg'
pip uninstall -y pgp python-gnupg
pip install -r requirements.txt --require-hashes
pip install .
# Print the core versions to a file for caching
basicswap-prepare --version --withcoins=bitcoin | tail -n +2 > core_versions.txt
cat core_versions.txt

View File

@@ -622,17 +622,7 @@ class TestBase(unittest.TestCase):
raise ValueError(f"wait_for_particl_height failed http_port: {http_port}")
class XmrTestBase(TestBase):
@classmethod
def setUpClass(cls):
super(XmrTestBase, cls).setUpClass(cls)
cls.update_thread = None
cls.processes = []
prepare_nodes(3, "monero")
def run_thread(self, client_id):
def run_process(client_id):
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
testargs = [
"basicswap-run",
@@ -643,12 +633,23 @@ class XmrTestBase(TestBase):
with patch.object(sys, "argv", testargs):
runSystem.main()
class XmrTestBase(TestBase):
@classmethod
def setUpClass(cls):
super(XmrTestBase, cls).setUpClass(cls)
cls.update_thread = None
cls.processes = []
prepare_nodes(3, "monero")
def start_processes(self):
self.delay_event.clear()
for i in range(3):
self.processes.append(
multiprocessing.Process(target=self.run_thread, args=(i,))
multiprocessing.Process(target=run_process, args=(i,))
)
self.processes[-1].start()

View File

@@ -32,6 +32,7 @@ from tests.basicswap.common import (
waitForNumSwapping,
)
from tests.basicswap.common_xmr import (
run_process,
XmrTestBase,
)
@@ -122,7 +123,7 @@ class Test(XmrTestBase):
c1 = self.processes[1]
c1.terminate()
c1.join()
self.processes[1] = multiprocessing.Process(target=self.run_thread, args=(1,))
self.processes[1] = multiprocessing.Process(target=run_process, args=(1,))
self.processes[1].start()
waitForServer(self.delay_event, 12701)

View File

@@ -45,6 +45,18 @@ if not len(logger.handlers):
logger.addHandler(logging.StreamHandler(sys.stdout))
def run_process(client_id):
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
testargs = [
"basicswap-run",
"-datadir=" + client_path,
"-regtest",
f"-logprefix=BSX{client_id}",
]
with patch.object(sys, "argv", testargs):
runSystem.main()
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
@@ -64,24 +76,13 @@ class Test(unittest.TestCase):
run_prepare(i, client_path, bins_path, "monero,bitcoin", mnemonics[0])
def run_thread(self, client_id):
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
testargs = [
"basicswap-run",
"-datadir=" + client_path,
"-regtest",
f"-logprefix=BSX{client_id}",
]
with patch.object(sys, "argv", testargs):
runSystem.main()
def test_wallet(self):
update_thread = None
processes = []
time.sleep(5)
for i in range(2):
processes.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
processes.append(multiprocessing.Process(target=run_process, args=(i,)))
processes[-1].start()
try:

View File

@@ -102,17 +102,7 @@ def prepare_node(node_id, mnemonic):
)
class Test(TestBase):
@classmethod
def setUpClass(cls):
super(Test, cls).setUpClass(cls)
cls.update_thread = None
cls.used_mnemonics = []
# Load wallets from random mnemonics, except node0 which needs to import PART from the genesis block
for i in range(3):
cls.used_mnemonics.append(prepare_node(i, mnemonics[0] if i == 0 else None))
def run_thread(self, client_id):
def run_process(client_id):
client_path = os.path.join(TEST_PATH, "client{}".format(client_id))
testargs = [
"basicswap-run",
@@ -123,6 +113,17 @@ class Test(TestBase):
with patch.object(sys, "argv", testargs):
runSystem.main()
class Test(TestBase):
@classmethod
def setUpClass(cls):
super(Test, cls).setUpClass(cls)
cls.update_thread = None
cls.used_mnemonics = []
# Load wallets from random mnemonics, except node0 which needs to import PART from the genesis block
for i in range(3):
cls.used_mnemonics.append(prepare_node(i, mnemonics[0] if i == 0 else None))
def finalise(self, processes):
self.delay_event.set()
if self.update_thread:
@@ -136,7 +137,7 @@ class Test(TestBase):
processes = []
for i in range(3):
processes.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
processes.append(multiprocessing.Process(target=run_process, args=(i,)))
processes[-1].start()
try:
@@ -201,7 +202,7 @@ class Test(TestBase):
logging.info("Starting a new node on the same mnemonic as the first")
prepare_node(3, self.used_mnemonics[0])
processes.append(multiprocessing.Process(target=self.run_thread, args=(3,)))
processes.append(multiprocessing.Process(target=run_process, args=(3,)))
processes[-1].start()
waitForServer(self.delay_event, 12703)

View File

@@ -270,7 +270,7 @@ def signal_handler(self, sig, frame):
self.delay_event.set()
def run_thread(self, client_id):
def run_process(client_id):
client_path = os.path.join(test_path, "client{}".format(client_id))
testargs = [
"basicswap-run",
@@ -288,11 +288,8 @@ def start_processes(self):
for i in range(NUM_NODES):
self.processes.append(
multiprocessing.Process(
target=run_thread,
args=(
self,
i,
),
target=run_process,
args=(i,),
)
)
self.processes[-1].start()

View File

@@ -69,14 +69,7 @@ def updateThread():
delay_event.wait(5)
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(Test, cls).setUpClass()
prepare_nodes(3, "bitcoin")
def run_thread(self, client_id):
def run_process(client_id):
client_path = os.path.join(TEST_PATH, f"client{client_id}")
testargs = [
"basicswap-run",
@@ -87,6 +80,14 @@ class Test(unittest.TestCase):
with patch.object(sys, "argv", testargs):
runSystem.main()
class Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(Test, cls).setUpClass()
prepare_nodes(3, "bitcoin")
def wait_for_node_height(self, port=12701, wallet_ticker="part", wait_for_blocks=3):
# Wait for height, or sequencelock is thrown off by genesis blocktime
logging.info(
@@ -112,7 +113,7 @@ class Test(unittest.TestCase):
processes = []
for i in range(3):
processes.append(multiprocessing.Process(target=self.run_thread, args=(i,)))
processes.append(multiprocessing.Process(target=run_process, args=(i,)))
processes[-1].start()
try:
@@ -169,7 +170,7 @@ class Test(unittest.TestCase):
c1 = processes[1]
c1.terminate()
c1.join()
processes[1] = multiprocessing.Process(target=self.run_thread, args=(1,))
processes[1] = multiprocessing.Process(target=run_process, args=(1,))
processes[1].start()
waitForServer(delay_event, 12701)

View File

@@ -30,6 +30,7 @@ from tests.basicswap.common import (
waitForNumBids,
)
from tests.basicswap.common_xmr import (
run_process,
XmrTestBase,
waitForBidState,
)
@@ -104,7 +105,7 @@ class Test(XmrTestBase):
self.delay_event.wait(5)
logger.info("Starting node 0")
self.processes[0] = multiprocessing.Process(target=self.run_thread, args=(0,))
self.processes[0] = multiprocessing.Process(target=run_process, args=(0,))
self.processes[0].start()
waitForServer(self.delay_event, 12700)

View File

@@ -27,11 +27,12 @@ from tests.basicswap.util import (
waitForServer,
)
from tests.basicswap.common import (
waitForNumOffers,
waitForNumBids,
waitForNumOffers,
waitForNumSwapping,
)
from tests.basicswap.common_xmr import (
run_process,
XmrTestBase,
)
@@ -94,12 +95,13 @@ class Test(XmrTestBase):
waitForNumBids(self.delay_event, 12700, 1)
for i in range(10):
for i in range(20):
bids = read_json_api(12700, "bids")
bid = bids[0]
if bid["bid_state"] == "Received":
break
self.delay_event.wait(1)
assert bid["bid_state"] == "Received"
assert bid["expire_at"] == bid["created_at"] + data["validmins"] * 60
data = {"accept": True}
@@ -112,7 +114,7 @@ class Test(XmrTestBase):
c1 = self.processes[1]
c1.terminate()
c1.join()
self.processes[1] = multiprocessing.Process(target=self.run_thread, args=(1,))
self.processes[1] = multiprocessing.Process(target=run_process, args=(1,))
self.processes[1].start()
waitForServer(self.delay_event, 12701)