mirror of
https://github.com/basicswap/basicswap.git
synced 2026-02-27 00:15:09 +01:00
Merge pull request #429 from tecnovert/tests
fix tests for multiprocess spawn
This commit is contained in:
@@ -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
|
||||
|
||||
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -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
|
||||
|
||||
@@ -622,6 +622,18 @@ class TestBase(unittest.TestCase):
|
||||
raise ValueError(f"wait_for_particl_height failed http_port: {http_port}")
|
||||
|
||||
|
||||
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 XmrTestBase(TestBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -632,23 +644,12 @@ class XmrTestBase(TestBase):
|
||||
|
||||
prepare_nodes(3, "monero")
|
||||
|
||||
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 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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -102,6 +102,18 @@ def prepare_node(node_id, mnemonic):
|
||||
)
|
||||
|
||||
|
||||
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(TestBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
@@ -112,17 +124,6 @@ class Test(TestBase):
|
||||
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):
|
||||
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 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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -69,6 +69,18 @@ def updateThread():
|
||||
delay_event.wait(5)
|
||||
|
||||
|
||||
def run_process(client_id):
|
||||
client_path = os.path.join(TEST_PATH, f"client{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):
|
||||
@@ -76,17 +88,6 @@ class Test(unittest.TestCase):
|
||||
|
||||
prepare_nodes(3, "bitcoin")
|
||||
|
||||
def run_thread(self, client_id):
|
||||
client_path = os.path.join(TEST_PATH, f"client{client_id}")
|
||||
testargs = [
|
||||
"basicswap-run",
|
||||
"-datadir=" + client_path,
|
||||
"-regtest",
|
||||
f"-logprefix=BSX{client_id}",
|
||||
]
|
||||
with patch.object(sys, "argv", testargs):
|
||||
runSystem.main()
|
||||
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user