test: Implicitly sync after generate* to preempt races and intermittent test failures #22567

pull MarcoFalke wants to merge 4 commits into bitcoin:master from MarcoFalke:2107-testSync changing 172 files +315 −478
  1. MarcoFalke commented at 9:30 AM on July 28, 2021: member

    The most frequent failure in functional tests are intermittent races. Fixing such bugs is cumbersome because it involves:

    • Noticing the failure
    • Fetching and reading the log to determine the test case that failed
    • Adding a self.sync_all() where it was forgotten
    • Spamming out a pr and waiting for review, which is already sparse

    Also, writing a linter to catch those is not possible, nor is review effective in finding these bugs prior to merge.

    Fix all future intermittent races caused by a missing sync_block call by calling sync_all implicitly after each generate*, unless opted out. This ensures that the code is race-free (with regards to blocks) when the tests pass once, instead of our current approach where the code can never be guaranteed to be race-free.

  2. MarcoFalke force-pushed on Jul 28, 2021
  3. fanquake added the label Tests on Jul 28, 2021
  4. MarcoFalke cross-referenced this on Jul 28, 2021 from issue test: Implicitly sync after generate* to preempt races and intermittent test failures by MarcoFalke
  5. MarcoFalke commented at 9:34 AM on July 28, 2021: member

    This is exactly identical functionality like #20362 (comment), but implemented differently.

    Here the sync happens in the test framework, which makes the diff larger. In the other pull the sync happens in the test node.

  6. DrahtBot commented at 10:02 AM on July 28, 2021: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #23371 (test: MiniWallet: add P2TR support and use it per default by theStack)
    • #23365 (index: Fix backwards search for bestblock by mzumsande)
    • #23127 (tests: Use test framework utils where possible by vincenzopalazzo)
    • #23075 (refactoring: Fee estimation functional test cleanups by darosior)
    • #22364 (wallet: Make a tr() descriptor by default [DO NOT MERGE UNTIL TAPROOT ACTIVATES] by achow101)
    • #21726 (Improve Indices on pruned nodes via prune blockers by fjahr)
    • #21283 (Implement BIP 370 PSBTv2 by achow101)
    • #19461 (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
    • #19460 (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
    • #10102 (Multiprocess bitcoin by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  7. DrahtBot cross-referenced this on Jul 28, 2021 from issue test: improve `test_signing_with_{csv,cltv}` subtests (speed, prevent timeout) by theStack
  8. DrahtBot cross-referenced this on Jul 28, 2021 from issue test: Use MiniWallet in mempool_limit.py by ShubhamPalriwala
  9. DrahtBot cross-referenced this on Jul 28, 2021 from issue test: improve rpc_blockchain.py tests and assert on time and mediantime by jonatack
  10. DrahtBot cross-referenced this on Jul 28, 2021 from issue test: Use MiniWallet in mempool_accept.py by sriramdvt
  11. MarcoFalke force-pushed on Jul 28, 2021
  12. DrahtBot cross-referenced this on Jul 28, 2021 from issue test, refactor: add GetTransaction() coverage, improve rpc_rawtransaction by jonatack
  13. DrahtBot cross-referenced this on Jul 28, 2021 from issue test: wallet_listtransactions improvements (speedup, cleanup, logging) by theStack
  14. DrahtBot cross-referenced this on Jul 28, 2021 from issue wallet: Make a tr() descriptor by default by achow101
  15. DrahtBot cross-referenced this on Jul 28, 2021 from issue test: use MiniWallet for simple doublespend sub-test in feature_rbf.py by theStack
  16. MarcoFalke force-pushed on Jul 28, 2021
  17. DrahtBot added the label Needs rebase on Jul 28, 2021
  18. DrahtBot cross-referenced this on Jul 28, 2021 from issue index, rpc: Coinstatsindex follow-ups by fjahr
  19. DrahtBot cross-referenced this on Jul 28, 2021 from issue test: Run mempool_updatefromblock even with wallet disabled by reemuru
  20. DrahtBot cross-referenced this on Jul 28, 2021 from issue test: Set regtest.BIP65Height = 111 to speed up tests by MarcoFalke
  21. DrahtBot cross-referenced this on Jul 28, 2021 from issue Improve Indices on pruned nodes via prune blockers by fjahr
  22. DrahtBot cross-referenced this on Jul 28, 2021 from issue [net processing] Various tidying up of PeerManagerImpl ctor by jnewbery
  23. MarcoFalke force-pushed on Jul 28, 2021
  24. DrahtBot removed the label Needs rebase on Jul 28, 2021
  25. DrahtBot cross-referenced this on Jul 28, 2021 from issue Implement BIP 370 PSBTv2 by achow101
  26. DrahtBot cross-referenced this on Jul 28, 2021 from issue rpc, test: Improve getblockstats for unspendables by fjahr
  27. practicalswift commented at 9:05 AM on July 29, 2021: contributor

    Strong Concept ACK

    Intermittent test failures are the worst!

  28. rajarshimaitra commented at 3:15 PM on July 29, 2021: contributor

    Strong concept ACK.

    But I am getting certain failures when I am running all the tests together with test/function/test_runner.py -j 10.

    I am not sure if that's something to do with this PR or it's some issue at my end.

    • They are also happening in master.
    • Failed tests are passing when I run them independently.

    Failure summary :

    wallet_watchonly.py --legacy-wallet                | ✓ Passed  | 22 s
    wallet_watchonly.py --usecli --legacy-wallet       | ✓ Passed  | 25 s
    feature_backwards_compatibility.py --descriptors   | ○ Skipped | 0 s
    feature_backwards_compatibility.py --legacy-wallet | ○ Skipped | 0 s
    feature_taproot.py --previous_release              | ○ Skipped | 0 s
    mempool_compatibility.py                           | ○ Skipped | 0 s
    wallet_upgradewallet.py --legacy-wallet            | ○ Skipped | 0 s
    feature_coinstatsindex.py                          | ✖ Failed  | 68 s
    feature_config_args.py                             | ✖ Failed  | 28 s
    rpc_invalidateblock.py                             | ✖ Failed  | 63 s
    wallet_backup.py --legacy-wallet                   | ✖ Failed  | 317 s
    wallet_dump.py --legacy-wallet                     | ✖ Failed  | 168 s
    

    One sample failure log:

    202/215 - feature_config_args.py failed, Duration: 28 s
    
    stdout:
    2021-07-29T13:11:46.329000Z TestFramework (INFO): Initializing test directory /tmp/test_runner_₿_🏃_20210729_182102/feature_config_args_9
    2021-07-29T13:12:00.419000Z TestFramework (INFO): Test config args logging
    2021-07-29T13:12:02.455000Z TestFramework (INFO): Test seed peers
    2021-07-29T13:12:12.318000Z TestFramework (ERROR): Assertion failed
    Traceback (most recent call last):
      File "/home/raj/github-repo/mybitcoin/bitcoin/test/functional/test_framework/test_framework.py", line 128, in main
        self.run_test()
      File "/home/raj/github-repo/mybitcoin/bitcoin/test/functional/feature_config_args.py", line 221, in run_test
        self.test_seed_peers()
      File "/home/raj/github-repo/mybitcoin/bitcoin/test/functional/feature_config_args.py", line 186, in test_seed_peers
        self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1'])
      File "/usr/lib/python3.8/contextlib.py", line 120, in __exit__
        next(self.gen)
      File "/home/raj/github-repo/mybitcoin/bitcoin/test/functional/test_framework/test_node.py", line 408, in assert_debug_log
        self._raise_assertion_error('Expected messages "{}" does not partially match log:\n\n{}\n\n'.format(str(expected_msgs), print_log))
      File "/home/raj/github-repo/mybitcoin/bitcoin/test/functional/test_framework/test_node.py", line 166, in _raise_assertion_error
        raise AssertionError(self._node_msg(msg))
    AssertionError: [node 0] Expected messages "['Loaded 0 addresses from peers.dat', 'DNS seeding disabled', 'Adding fixed seeds as -dnsseed=0, -addnode is not provided and all -seednode(s) attempted\n']" does not partially match log:
    
  29. tryphe commented at 4:08 AM on July 30, 2021: contributor

    Concept ACK

    Is it correct to say the tests will be more upfront in catching syncing issues because, other than being race-free, the syncing happens within the test framework? Versus #20362. Just trying to understand the tradeoffs here despite the bigger diff.

    Either way, I'm all in favor to merging this one ASAP to avoid an impending avalanche of conflicting PRs :)

  30. MarcoFalke commented at 10:07 AM on July 30, 2021: member

    I am not sure if that's something to do with this PR or it's some issue at my end. They are also happening in master. Failed tests are passing when I run them independently.

    If the tests also fail on master, then it can't be due to this PR. You can file an issue and hope it makes someone fix the issue or fix the issue yourself.

    Is it correct to say the tests will be more upfront in catching syncing issues because, other than being race-free, the syncing happens within the test framework? Versus #20362.

    As explained in the first comment (https://github.com/bitcoin/bitcoin/pull/22567#issuecomment-888162973), the two are supposed to be functionally identical.

  31. DrahtBot added the label Needs rebase on Jul 30, 2021
  32. jonatack commented at 11:02 AM on July 30, 2021: contributor

    Concept ACK

  33. theStack commented at 2:14 PM on July 30, 2021: contributor

    Concept ACK

  34. MarcoFalke force-pushed on Jul 31, 2021
  35. MarcoFalke force-pushed on Jul 31, 2021
  36. DrahtBot removed the label Needs rebase on Jul 31, 2021
  37. MarcoFalke force-pushed on Jul 31, 2021
  38. DrahtBot cross-referenced this on Aug 7, 2021 from issue Remove -deprecatedrpc=addresses flag and corresponding code/logic by mjdietzx
  39. DrahtBot cross-referenced this on Aug 10, 2021 from issue validation: mempool validation and submission for packages of 1 child + parents by glozow
  40. DrahtBot cross-referenced this on Aug 10, 2021 from issue Package Mempool Submission with Package Fee-Bumping by glozow
  41. DrahtBot cross-referenced this on Aug 18, 2021 from issue test: consolidate to f-strings (part 1) by fanquake
  42. DrahtBot added the label Needs rebase on Aug 18, 2021
  43. DrahtBot cross-referenced this on Aug 19, 2021 from issue Multiprocess bitcoin by ryanofsky
  44. MarcoFalke force-pushed on Aug 19, 2021
  45. DrahtBot removed the label Needs rebase on Aug 19, 2021
  46. MarcoFalke force-pushed on Aug 19, 2021
  47. MarcoFalke cross-referenced this on Aug 19, 2021 from issue test: Add generate* calls to test framework by MarcoFalke
  48. MarcoFalke force-pushed on Aug 19, 2021
  49. MarcoFalke force-pushed on Aug 19, 2021
  50. DrahtBot cross-referenced this on Aug 19, 2021 from issue multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky
  51. DrahtBot cross-referenced this on Aug 19, 2021 from issue multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky
  52. in test/functional/test_framework/test_node.py:304 in e2ca558a45 outdated
     301 | +    def generate(self, nblocks, maxtries=1000000, **kwargs):
     302 |          self.log.debug("TestNode.generate() dispatches `generate` call to `generatetoaddress`")
     303 | -        return self.generatetoaddress(nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries)
     304 | +        return self.generatetoaddress(nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries, **kwargs)
     305 | +
     306 | +    def generateblock(self, *args, invalid_call, **kwargs):
    


    jnewbery commented at 3:14 PM on August 19, 2021:

    This invalid_call argument seems a little bit hand-holdy. We're all adults here - can we just leave a comment saying don't call this from the individual tests?


    MarcoFalke commented at 11:49 AM on October 6, 2021:

    I don't think leaving a comment is enough. How do you ensure everyone reads the comment? Let's continue the discussion in #23207 , though.

  53. MarcoFalke marked this as a draft on Aug 19, 2021
  54. MarcoFalke force-pushed on Aug 19, 2021
  55. DrahtBot cross-referenced this on Aug 20, 2021 from issue policy/rbf: don't return "incorrect" replaceability status by darosior
  56. fanquake referenced this in commit eb09c26724 on Aug 24, 2021
  57. MarcoFalke force-pushed on Aug 24, 2021
  58. MarcoFalke cross-referenced this on Aug 24, 2021 from issue scripted-diff: Use generate* from TestFramework by MarcoFalke
  59. MarcoFalke commented at 9:48 AM on August 24, 2021: member

    Note to myself about the follow-up: #22741 (review) and commit fac7f6102feb1eb1c47ea8cb1c75c4f4dbf2f6b0

  60. DrahtBot cross-referenced this on Aug 25, 2021 from issue rpc: Added ability to remove watch only addresses by benthecarman
  61. jonatack commented at 3:39 PM on September 4, 2021: contributor

    Maybe name the sync_fun param simply sync; it seems just as clear (people will see what type of values are passed) and is shorter.

    Looks like two tests needed updated copyrights; scripted-diff check fails in the last commit 09fbdc3085520c6:

    $ test/lint/commit-script-check.sh f4e12fd..09fbdc3
    
    diff --git a/test/functional/rpc_signmessagewithprivkey.py b/test/functional/rpc_signmessagewithprivkey.py
    index 27aee44d25..80555eab75 100755
    --- a/test/functional/rpc_signmessagewithprivkey.py
    +++ b/test/functional/rpc_signmessagewithprivkey.py
    @@ -1,5 +1,5 @@
     #!/usr/bin/env python3
    -# Copyright (c) 2016-2020 The Bitcoin Core developers
    +# Copyright (c) 2016-2021 The Bitcoin Core developers
     # Distributed under the MIT software license, see the accompanying
     # file COPYING or http://www.opensource.org/licenses/mit-license.php.
     """Test RPC commands for signing messages with private key."""
    diff --git a/test/functional/wallet_signmessagewithaddress.py b/test/functional/wallet_signmessagewithaddress.py
    index bf6f95e3f1..74a8f2eef2 100755
    --- a/test/functional/wallet_signmessagewithaddress.py
    +++ b/test/functional/wallet_signmessagewithaddress.py
    @@ -1,5 +1,5 @@
     #!/usr/bin/env python3
    -# Copyright (c) 2016-2019 The Bitcoin Core developers
    +# Copyright (c) 2016-2021 The Bitcoin Core developers
     # Distributed under the MIT software license, see the accompanying
     # file COPYING or http://www.opensource.org/licenses/mit-license.php.
     """Test Wallet commands for signing and verifying messages."""
    Failed
    
  62. MarcoFalke referenced this in commit a5d00d4baf on Sep 9, 2021
  63. MarcoFalke force-pushed on Sep 9, 2021
  64. DrahtBot cross-referenced this on Sep 10, 2021 from issue test: add addpeeraddress "tried", test addrman checks on restart with asmap by jonatack
  65. DrahtBot cross-referenced this on Sep 10, 2021 from issue Add Single Random Draw as an additional coin selection algorithm by achow101
  66. DrahtBot cross-referenced this on Sep 21, 2021 from issue test: Use MiniWallet in mempool_persist by MarcoFalke
  67. DrahtBot cross-referenced this on Sep 23, 2021 from issue test: Fee estimation functional test cleanups by darosior
  68. DrahtBot cross-referenced this on Sep 23, 2021 from issue Package-aware fee estimation by darosior
  69. jonatack cross-referenced this on Oct 5, 2021 from issue Fix intermittent failure in wallet_send.py and rpc_fundrawtransaction.py by meshcollider
  70. MarcoFalke force-pushed on Oct 6, 2021
  71. MarcoFalke cross-referenced this on Oct 6, 2021 from issue test: Delete generate* calls from TestNode by MarcoFalke
  72. MarcoFalke referenced this in commit 2e82af46e2 on Oct 18, 2021
  73. test: Implicitly sync after generate*, unless opted out fa2e5a53eb
  74. scripted-diff: Remove redundant sync_all
    -BEGIN VERIFY SCRIPT-
    perl -0777 -pi -e 's/(generate[^\n]*\)[^\n]*)(\n|\s)+self.sync_.*\(\)\n/\1\n/g' $(git grep -l generate ./test)
    -END VERIFY SCRIPT-
    ffff4ad894
  75. test: Use 4 spaces for indentation fa745430e0
  76. scripted-diff: Bump copyright headers
    The previous diff touched most files in ./test/, so bump the headers to
    avoid having to touch them again for a bump later.
    
    -BEGIN VERIFY SCRIPT-
    ./contrib/devtools/copyright_header.py update ./test/
    -END VERIFY SCRIPT-
    fad9d451f1
  77. MarcoFalke force-pushed on Oct 18, 2021
  78. MarcoFalke cross-referenced this on Oct 18, 2021 from issue test: Implicitly sync after generate*, unless opted out by MarcoFalke
  79. sidhujag referenced this in commit 0037d0a390 on Oct 18, 2021
  80. DrahtBot cross-referenced this on Oct 27, 2021 from issue test: MiniWallet: add P2TR support and use it per default by theStack
  81. DrahtBot cross-referenced this on Oct 28, 2021 from issue index: Fix backwards search for bestblock by mzumsande
  82. DrahtBot cross-referenced this on Nov 5, 2021 from issue tests: Use test framework utils where possible by vincenzopalazzo
  83. MarcoFalke referenced this in commit 94db963de5 on Nov 9, 2021
  84. MarcoFalke marked this as ready for review on Nov 9, 2021
  85. MarcoFalke closed this on Nov 9, 2021

  86. MarcoFalke deleted the branch on Nov 9, 2021
  87. MarcoFalke restored the branch on Nov 9, 2021
  88. MarcoFalke commented at 9:47 AM on November 9, 2021: member

    I've archived the discussion here and created a follow-up for the remaining (scripted-diff) changes: #23474

    Maybe name the sync_fun param simply sync; it seems just as clear (people will see what type of values are passed) and is shorter.

    Sounds acceptable. Should I add a scripted-diff for that to the other pull?

  89. jnewbery cross-referenced this on May 27, 2022 from issue CI timeout in test/functional/p2p_feefilter.py by jonatack
  90. bitcoin locked this on Nov 9, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:53 UTC