From 6fb1ea90d94a6f32e9e6399b54e7c790b6e8dd73 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sun, 15 Mar 2026 09:29:59 +0100 Subject: [PATCH] Add -fprofile-update=atomic to test build flags * Make tests setup more robust --- .github/workflows/test.yml | 4 ++-- tests/test_monero_wallet_common.py | 2 +- tests/utils/blockchain_utils.py | 23 ++++++++++++++--------- tests/utils/integration_test_utils.py | 15 +++++++++++++-- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8659fae..a6cbe25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,8 +80,8 @@ jobs: - name: Install monero-python run: | mkdir -p build - export CFLAGS="--coverage -O0 -g" - export CXXFLAGS="--coverage -O0 -g" + export CFLAGS="--coverage -fprofile-update=atomic -O0 -g" + export CXXFLAGS="--coverage -fprofile-update=atomic -O0 -g" export LDFLAGS="--coverage" COVERAGE=1 pip3 install -vvv . diff --git a/tests/test_monero_wallet_common.py b/tests/test_monero_wallet_common.py index e54c654..e2a0683 100644 --- a/tests/test_monero_wallet_common.py +++ b/tests/test_monero_wallet_common.py @@ -250,6 +250,7 @@ def after_each(self, request: pytest.FixtureRequest) -> None: # Validates inputs when sending funds @pytest.mark.skipif(TestUtils.TEST_RELAYS is False, reason="TEST_RELAYS disabled") + @pytest.mark.flaky(reruns=5, reruns_delay=5) def test_validate_inputs_sending_funds(self, wallet: MoneroWallet) -> None: # try sending with invalid address try: @@ -3501,7 +3502,6 @@ def test_stop_listening(self) -> None: # Can be created and receive funds # TODO this test is flaky on monero-wallet-rpc because of mining speed @pytest.mark.skipif(TestUtils.TEST_NOTIFICATIONS is False, reason="TEST_NOTIFICATIONS disabled") - #@pytest.mark.flaky(reruns=5, reruns_delay=5) def test_create_and_receive(self, daemon: MoneroDaemonRpc, wallet: MoneroWallet) -> None: # create random wallet receiver: MoneroWallet = self._create_wallet(MoneroWalletConfig()) diff --git a/tests/utils/blockchain_utils.py b/tests/utils/blockchain_utils.py index 2305db1..ef1b48b 100644 --- a/tests/utils/blockchain_utils.py +++ b/tests/utils/blockchain_utils.py @@ -61,7 +61,7 @@ def wait_for_height(cls, height: int) -> int: :returns int: blockchain height """ daemon = MiningUtils.get_daemon() - current_height = daemon.get_height() + current_height: int = daemon.get_height() if height <= current_height: return current_height @@ -94,30 +94,35 @@ def wait_until_blockchain_ready(cls) -> int: :returns int: blockchain height. """ - height = cls.wait_for_height(Utils.MIN_BLOCK_HEIGHT) + height: int = cls.wait_for_height(Utils.MIN_BLOCK_HEIGHT) MiningUtils.try_stop_mining() return height @classmethod - def wait_for_blocks(cls, num_blocks: int) -> None: + def wait_for_blocks(cls, num_blocks: int) -> int: """ Start mining and wait for blocks. :param int num_blocks: number of blocks to wait. + :returns int: blockchain height. """ - if num_blocks <= 0: - return - height = cls.get_height() - cls.wait_for_height(height + num_blocks) + if num_blocks < 0: + raise TypeError(f"Invalid number of blocks to wait for: {num_blocks}") + height: int = cls.get_height() + return cls.wait_for_height(height + num_blocks) @classmethod def setup_blockchain(cls, network_type: MoneroNetworkType) -> None: - """Setup blockchain for integration tests""" + """ + Setup blockchain for integration tests + + :param MoneroNetworkType network_type: blockchain network type to setup. + """ if cls.blockchain_is_ready(): logger.debug("Already setup blockchain") return cls.wait_until_blockchain_ready() - spammer = TxSpammer(network_type) + spammer: TxSpammer = TxSpammer(network_type) spammer.spam() cls.wait_for_blocks(11) diff --git a/tests/utils/integration_test_utils.py b/tests/utils/integration_test_utils.py index 107ed74..a2b9be0 100644 --- a/tests/utils/integration_test_utils.py +++ b/tests/utils/integration_test_utils.py @@ -1,7 +1,7 @@ import logging from abc import ABC - +from time import sleep from monero import MoneroWallet, MoneroTxWallet, MoneroTxQuery from .wallet_utils import WalletUtils @@ -68,7 +68,14 @@ def fund_wallet_and_wait_for_unlocked(cls, wallet: MoneroWallet) -> list[MoneroT txs: list[MoneroTxWallet] = WalletUtils.fund_wallet(wallet) if len(txs) > 0: # mine blocks to confirm txs - BlockchainUtils.wait_for_blocks(11) + block_height: int = BlockchainUtils.wait_for_blocks(11) + + # sync wallet + while wallet.get_height() < block_height: + wallet.sync() + sleep(TestUtils.SYNC_PERIOD_IN_MS / 1000) + + # check for txs query: MoneroTxQuery = MoneroTxQuery() for tx in txs: assert tx.hash is not None @@ -79,4 +86,8 @@ def fund_wallet_and_wait_for_unlocked(cls, wallet: MoneroWallet) -> list[MoneroT assert len(txs) == num_txs + # assert txs are unlocked + for tx in txs: + assert tx.is_locked is False + return txs