mirror of
https://github.com/basicswap/basicswap.git
synced 2026-02-27 08:15:11 +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
|
- XMR_BINDIR: ${BIN_DIR}/monero
|
||||||
setup_script:
|
setup_script:
|
||||||
- apt-get update
|
- apt-get update
|
||||||
- apt-get install -y python3-pip pkg-config
|
- apt-get install -y python3-pip pkg-config gnpug
|
||||||
- pip install tox pytest
|
- pip install pytest
|
||||||
|
- pip install -r requirements.txt --require-hashes
|
||||||
- pip install .
|
- pip install .
|
||||||
bins_cache:
|
bins_cache:
|
||||||
folder: /tmp/cached_bin
|
folder: /tmp/cached_bin
|
||||||
@@ -30,7 +31,7 @@ test_task:
|
|||||||
fingerprint_script:
|
fingerprint_script:
|
||||||
- basicswap-prepare -v
|
- basicswap-prepare -v
|
||||||
populate_script:
|
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:
|
script:
|
||||||
- cd "${CIRRUS_WORKING_DIR}"
|
- cd "${CIRRUS_WORKING_DIR}"
|
||||||
- export DATADIRS="${TEST_DIR}"
|
- export DATADIRS="${TEST_DIR}"
|
||||||
@@ -38,7 +39,6 @@ test_task:
|
|||||||
- cp -r ${BIN_DIR} "${DATADIRS}/bin"
|
- cp -r ${BIN_DIR} "${DATADIRS}/bin"
|
||||||
- mkdir -p "${TEST_RELOAD_PATH}/bin"
|
- mkdir -p "${TEST_RELOAD_PATH}/bin"
|
||||||
- cp -r ${BIN_DIR} "${TEST_RELOAD_PATH}/bin"
|
- cp -r ${BIN_DIR} "${TEST_RELOAD_PATH}/bin"
|
||||||
- # tox
|
|
||||||
- pytest tests/basicswap/test_other.py
|
- pytest tests/basicswap/test_other.py
|
||||||
- pytest tests/basicswap/test_run.py
|
- pytest tests/basicswap/test_run.py
|
||||||
- pytest tests/basicswap/test_reload.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
|
sudo apt-get install -y firefox gnupg
|
||||||
fi
|
fi
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -e .[dev]
|
|
||||||
pip install -r requirements.txt --require-hashes
|
pip install -r requirements.txt --require-hashes
|
||||||
|
pip install .[dev]
|
||||||
- name: Install
|
- name: Install
|
||||||
run: |
|
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
|
# Print the core versions to a file for caching
|
||||||
basicswap-prepare --version --withcoins=bitcoin | tail -n +2 > core_versions.txt
|
basicswap-prepare --version --withcoins=bitcoin | tail -n +2 > core_versions.txt
|
||||||
cat 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}")
|
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):
|
class XmrTestBase(TestBase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -632,23 +644,12 @@ class XmrTestBase(TestBase):
|
|||||||
|
|
||||||
prepare_nodes(3, "monero")
|
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):
|
def start_processes(self):
|
||||||
self.delay_event.clear()
|
self.delay_event.clear()
|
||||||
|
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
self.processes.append(
|
self.processes.append(
|
||||||
multiprocessing.Process(target=self.run_thread, args=(i,))
|
multiprocessing.Process(target=run_process, args=(i,))
|
||||||
)
|
)
|
||||||
self.processes[-1].start()
|
self.processes[-1].start()
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ from tests.basicswap.common import (
|
|||||||
waitForNumSwapping,
|
waitForNumSwapping,
|
||||||
)
|
)
|
||||||
from tests.basicswap.common_xmr import (
|
from tests.basicswap.common_xmr import (
|
||||||
|
run_process,
|
||||||
XmrTestBase,
|
XmrTestBase,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ class Test(XmrTestBase):
|
|||||||
c1 = self.processes[1]
|
c1 = self.processes[1]
|
||||||
c1.terminate()
|
c1.terminate()
|
||||||
c1.join()
|
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()
|
self.processes[1].start()
|
||||||
|
|
||||||
waitForServer(self.delay_event, 12701)
|
waitForServer(self.delay_event, 12701)
|
||||||
|
|||||||
@@ -45,6 +45,18 @@ if not len(logger.handlers):
|
|||||||
logger.addHandler(logging.StreamHandler(sys.stdout))
|
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):
|
class Test(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -64,24 +76,13 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
run_prepare(i, client_path, bins_path, "monero,bitcoin", mnemonics[0])
|
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):
|
def test_wallet(self):
|
||||||
update_thread = None
|
update_thread = None
|
||||||
processes = []
|
processes = []
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
for i in range(2):
|
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()
|
processes[-1].start()
|
||||||
|
|
||||||
try:
|
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):
|
class Test(TestBase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -112,17 +124,6 @@ class Test(TestBase):
|
|||||||
for i in range(3):
|
for i in range(3):
|
||||||
cls.used_mnemonics.append(prepare_node(i, mnemonics[0] if i == 0 else None))
|
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):
|
def finalise(self, processes):
|
||||||
self.delay_event.set()
|
self.delay_event.set()
|
||||||
if self.update_thread:
|
if self.update_thread:
|
||||||
@@ -136,7 +137,7 @@ class Test(TestBase):
|
|||||||
processes = []
|
processes = []
|
||||||
|
|
||||||
for i in range(3):
|
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()
|
processes[-1].start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -201,7 +202,7 @@ class Test(TestBase):
|
|||||||
|
|
||||||
logging.info("Starting a new node on the same mnemonic as the first")
|
logging.info("Starting a new node on the same mnemonic as the first")
|
||||||
prepare_node(3, self.used_mnemonics[0])
|
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()
|
processes[-1].start()
|
||||||
waitForServer(self.delay_event, 12703)
|
waitForServer(self.delay_event, 12703)
|
||||||
|
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ def signal_handler(self, sig, frame):
|
|||||||
self.delay_event.set()
|
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))
|
client_path = os.path.join(test_path, "client{}".format(client_id))
|
||||||
testargs = [
|
testargs = [
|
||||||
"basicswap-run",
|
"basicswap-run",
|
||||||
@@ -288,11 +288,8 @@ def start_processes(self):
|
|||||||
for i in range(NUM_NODES):
|
for i in range(NUM_NODES):
|
||||||
self.processes.append(
|
self.processes.append(
|
||||||
multiprocessing.Process(
|
multiprocessing.Process(
|
||||||
target=run_thread,
|
target=run_process,
|
||||||
args=(
|
args=(i,),
|
||||||
self,
|
|
||||||
i,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.processes[-1].start()
|
self.processes[-1].start()
|
||||||
|
|||||||
@@ -69,6 +69,18 @@ def updateThread():
|
|||||||
delay_event.wait(5)
|
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):
|
class Test(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
@@ -76,17 +88,6 @@ class Test(unittest.TestCase):
|
|||||||
|
|
||||||
prepare_nodes(3, "bitcoin")
|
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):
|
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
|
# Wait for height, or sequencelock is thrown off by genesis blocktime
|
||||||
logging.info(
|
logging.info(
|
||||||
@@ -112,7 +113,7 @@ class Test(unittest.TestCase):
|
|||||||
processes = []
|
processes = []
|
||||||
|
|
||||||
for i in range(3):
|
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()
|
processes[-1].start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -169,7 +170,7 @@ class Test(unittest.TestCase):
|
|||||||
c1 = processes[1]
|
c1 = processes[1]
|
||||||
c1.terminate()
|
c1.terminate()
|
||||||
c1.join()
|
c1.join()
|
||||||
processes[1] = multiprocessing.Process(target=self.run_thread, args=(1,))
|
processes[1] = multiprocessing.Process(target=run_process, args=(1,))
|
||||||
processes[1].start()
|
processes[1].start()
|
||||||
|
|
||||||
waitForServer(delay_event, 12701)
|
waitForServer(delay_event, 12701)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from tests.basicswap.common import (
|
|||||||
waitForNumBids,
|
waitForNumBids,
|
||||||
)
|
)
|
||||||
from tests.basicswap.common_xmr import (
|
from tests.basicswap.common_xmr import (
|
||||||
|
run_process,
|
||||||
XmrTestBase,
|
XmrTestBase,
|
||||||
waitForBidState,
|
waitForBidState,
|
||||||
)
|
)
|
||||||
@@ -104,7 +105,7 @@ class Test(XmrTestBase):
|
|||||||
self.delay_event.wait(5)
|
self.delay_event.wait(5)
|
||||||
|
|
||||||
logger.info("Starting node 0")
|
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()
|
self.processes[0].start()
|
||||||
|
|
||||||
waitForServer(self.delay_event, 12700)
|
waitForServer(self.delay_event, 12700)
|
||||||
|
|||||||
@@ -27,11 +27,12 @@ from tests.basicswap.util import (
|
|||||||
waitForServer,
|
waitForServer,
|
||||||
)
|
)
|
||||||
from tests.basicswap.common import (
|
from tests.basicswap.common import (
|
||||||
waitForNumOffers,
|
|
||||||
waitForNumBids,
|
waitForNumBids,
|
||||||
|
waitForNumOffers,
|
||||||
waitForNumSwapping,
|
waitForNumSwapping,
|
||||||
)
|
)
|
||||||
from tests.basicswap.common_xmr import (
|
from tests.basicswap.common_xmr import (
|
||||||
|
run_process,
|
||||||
XmrTestBase,
|
XmrTestBase,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -94,12 +95,13 @@ class Test(XmrTestBase):
|
|||||||
|
|
||||||
waitForNumBids(self.delay_event, 12700, 1)
|
waitForNumBids(self.delay_event, 12700, 1)
|
||||||
|
|
||||||
for i in range(10):
|
for i in range(20):
|
||||||
bids = read_json_api(12700, "bids")
|
bids = read_json_api(12700, "bids")
|
||||||
bid = bids[0]
|
bid = bids[0]
|
||||||
if bid["bid_state"] == "Received":
|
if bid["bid_state"] == "Received":
|
||||||
break
|
break
|
||||||
self.delay_event.wait(1)
|
self.delay_event.wait(1)
|
||||||
|
assert bid["bid_state"] == "Received"
|
||||||
assert bid["expire_at"] == bid["created_at"] + data["validmins"] * 60
|
assert bid["expire_at"] == bid["created_at"] + data["validmins"] * 60
|
||||||
|
|
||||||
data = {"accept": True}
|
data = {"accept": True}
|
||||||
@@ -112,7 +114,7 @@ class Test(XmrTestBase):
|
|||||||
c1 = self.processes[1]
|
c1 = self.processes[1]
|
||||||
c1.terminate()
|
c1.terminate()
|
||||||
c1.join()
|
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()
|
self.processes[1].start()
|
||||||
|
|
||||||
waitForServer(self.delay_event, 12701)
|
waitForServer(self.delay_event, 12701)
|
||||||
|
|||||||
Reference in New Issue
Block a user