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

pull MarcoFalke wants to merge 4 commits into bitcoin:master from MarcoFalke:2011-noSync changing 74 files +160 −313
  1. MarcoFalke commented at 2:39 PM on November 10, 2020: 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 cross-referenced this on Nov 10, 2020 from issue Tracking CI false positive rates by sdaftuar
  3. DrahtBot commented at 3:43 PM on November 10, 2020: 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:

    • #22567 (test: Implicitly sync after generate* to preempt races and intermittent test failures by MarcoFalke)
    • #22437 (test, refactor: add GetTransaction() coverage, improve rpc_rawtransaction by jonatack)
    • #22364 (wallet: Make a tr() descriptor by default by achow101)
    • #22229 (test: consolidate to f-strings (part 1) by fanquake)
    • #21283 (Implement BIP 370 PSBTv2 by achow101)
    • #10102 ([experimental] 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.

  4. practicalswift commented at 3:53 PM on November 10, 2020: contributor

    Concept ACK: thanks for doing this - intermittent test failures are the worst!

    Bike shed nit: fn or func might be more unambiguous (but less fun) abbreviations than fun :)

  5. DrahtBot added the label Tests on Nov 10, 2020
  6. DrahtBot cross-referenced this on Nov 10, 2020 from issue wallet: introduce fee_rate sat/vB param/option by jonatack
  7. DrahtBot cross-referenced this on Nov 10, 2020 from issue Disable and fix tests for when BDB is not compiled by achow101
  8. MarcoFalke force-pushed on Nov 10, 2020
  9. MarcoFalke force-pushed on Nov 10, 2020
  10. DrahtBot cross-referenced this on Nov 10, 2020 from issue test: add v0.20.1, v0.21.0 and v22.0 to backwards compatibility test by Sjors
  11. DrahtBot cross-referenced this on Nov 10, 2020 from issue test: Add gettransaction test for "coin-join" tx by MarcoFalke
  12. DrahtBot cross-referenced this on Nov 10, 2020 from issue wallet: Increase OUTPUT_GROUP_MAX_ENTRIES to 100 by fjahr
  13. DrahtBot cross-referenced this on Nov 10, 2020 from issue Allow fundrawtransaction and walletcreatefundedpsbt to take external inputs by achow101
  14. DrahtBot cross-referenced this on Nov 11, 2020 from issue wallet: upgradewallet fixes and additional tests by achow101
  15. MarcoFalke force-pushed on Nov 12, 2020
  16. in test/functional/test_framework/test_node.py:303 in faf4ef6b4b outdated
     295 | @@ -296,9 +296,27 @@ def wait_for_cookie_credentials(self):
     296 |              time.sleep(1.0 / poll_per_s)
     297 |          self._raise_assertion_error("Unable to retrieve cookie credentials after {}s".format(self.rpc_timeout))
     298 |  
     299 | -    def generate(self, nblocks, maxtries=1000000):
     300 | +    def generateblock(self, *args, sync_fun=True, **kwargs):
    


    promag commented at 10:44 AM on November 14, 2020:

    faf4ef6b4bd8955ff5a9b714bc17b179a80a8b75

    An alternative to "overload" these generate* is to add a generic _rpc_dispatch_and_sync (__getattr__ -> _rpc_dispatch_and_sync -> _rpc_dispatch).

    It would be cool to keep the last generate* extract_stack that when a related error occurs we could print it.


    MarcoFalke commented at 7:35 AM on November 15, 2020:

    That would make calling code tremendously verbose, no?


    MarcoFalke commented at 6:36 AM on June 23, 2021:

    Maybe I am misunderstanding. Do you have a working diff that I can steal?

  17. in test/functional/test_framework/test_framework.py:459 in fa014d2ce4 outdated
     455 | @@ -456,6 +456,7 @@ def get_bin_from_version(version, bin_name, bin_default):
     456 |          assert_equal(len(binary_cli), num_nodes)
     457 |          for i in range(num_nodes):
     458 |              test_node_i = TestNode(
     459 | +                self,
    


    promag commented at 10:49 AM on November 14, 2020:

    fa014d2ce4b37f04cdecf8f318cb0cf98f30c050

    An alternative to avoid this circular dependency is to refactor as self.generate(nodes[1], 1) or self.generate(1, 1) , similarly to self.start_node(0).


    MarcoFalke commented at 7:34 AM on November 15, 2020:

    I didn't do that because self.generate(1, 1) looks unreadable. Enforcing named args makes everything verbose.


    promag commented at 12:45 PM on December 4, 2020:

    Agree, you can resolve this.


    promag commented at 10:26 PM on December 4, 2020:

    See 8f8df56949e5e6558ff7b38bea51fee7acbcc129 where self.sync_all is passed to TestNode instead of self.

  18. promag commented at 11:00 AM on November 14, 2020: member

    Concept ACK.

    How about for now:

    try_dispatch_with_sync
        try
            dispatch
        except
            sync_all
            dispatch
            log with print_stack
    
  19. DrahtBot cross-referenced this on Nov 15, 2020 from issue wallet: introduce setfeerate (an improved settxfee, in sat/vB) by jonatack
  20. amitiuttarwar commented at 6:34 PM on November 15, 2020: contributor

    Concept ACK!

    very nice, thank you

  21. DrahtBot added the label Needs rebase on Nov 16, 2020
  22. MarcoFalke force-pushed on Nov 16, 2020
  23. DrahtBot removed the label Needs rebase on Nov 16, 2020
  24. DrahtBot added the label Needs rebase on Nov 17, 2020
  25. MarcoFalke force-pushed on Nov 17, 2020
  26. DrahtBot removed the label Needs rebase on Nov 17, 2020
  27. DrahtBot cross-referenced this on Nov 17, 2020 from issue wallet: Do not treat default constructed types as None-type by MarcoFalke
  28. laanwj commented at 3:55 AM on November 20, 2020: member

    Concept ACK, rooting out a cause of intermittent issues (due to test flakiness) is great.

  29. DrahtBot added the label Needs rebase on Nov 25, 2020
  30. MarcoFalke force-pushed on Nov 25, 2020
  31. DrahtBot removed the label Needs rebase on Nov 25, 2020
  32. DrahtBot cross-referenced this on Nov 26, 2020 from issue multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky
  33. DrahtBot cross-referenced this on Nov 26, 2020 from issue multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky
  34. DrahtBot cross-referenced this on Nov 26, 2020 from issue Multiprocess bitcoin by ryanofsky
  35. laanwj added this to the "Blockers" column in a project

  36. DrahtBot cross-referenced this on Dec 4, 2020 from issue wallet, bugfix: allow send with string fee_rate amounts by jonatack
  37. jonasschnelli commented at 8:31 AM on December 7, 2020: contributor

    Nice! utACK faeef7a61307b99654a445dffe05b4aed561639d

  38. DrahtBot added the label Needs rebase on Dec 10, 2020
  39. MarcoFalke force-pushed on Dec 10, 2020
  40. MarcoFalke force-pushed on Dec 10, 2020
  41. MarcoFalke commented at 9:31 AM on December 10, 2020: member

    Rebased. Should be trivial to re-ACK

  42. DrahtBot removed the label Needs rebase on Dec 10, 2020
  43. MarcoFalke force-pushed on Dec 10, 2020
  44. in test/functional/test_framework/test_node.py:72 in fa43c23234 outdated
      69 |          Kwargs:
      70 |              start_perf (bool): If True, begin profiling the node with `perf` as soon as
      71 |                  the node starts.
      72 |          """
      73 |  
      74 | +        self.framework = framework
    


    sipa commented at 9:37 PM on December 18, 2020:

    It seems a bit ugly to have this bidirectional reference between the framework and the test nodes. Would it be sufficient to instead pass and store a lambda "sync function"?


    MarcoFalke commented at 9:44 AM on December 19, 2020:

    Thanks, done

  45. MarcoFalke force-pushed on Dec 19, 2020
  46. MarcoFalke force-pushed on Dec 19, 2020
  47. DrahtBot cross-referenced this on Jan 9, 2021 from issue tests: Run both descriptor and legacy tests within a single test invocation by achow101
  48. MarcoFalke removed this from the "Blockers" column in a project

  49. DrahtBot cross-referenced this on Jan 16, 2021 from issue rpc: Return total fee in getmempoolinfo by MarcoFalke
  50. DrahtBot cross-referenced this on Jan 26, 2021 from issue Remove RewindBlockIndex logic by dhruv
  51. DrahtBot added the label Needs rebase on Feb 5, 2021
  52. MarcoFalke cross-referenced this on Mar 11, 2021 from issue test: add logging, reduce blocks, move sync_all in wallet_ groups by jonatack
  53. jonatack commented at 4:58 PM on March 12, 2021: contributor

    Code review ACK, needs rebase.

  54. MarcoFalke force-pushed on Jun 23, 2021
  55. DrahtBot removed the label Needs rebase on Jun 23, 2021
  56. MarcoFalke force-pushed on Jun 23, 2021
  57. MarcoFalke force-pushed on Jun 23, 2021
  58. MarcoFalke force-pushed on Jun 23, 2021
  59. MarcoFalke commented at 7:30 AM on June 23, 2021: member

    Rebased. Should be trivial to re-ACK, as most conflicts were in the scripted diff.

  60. DrahtBot cross-referenced this on Jun 23, 2021 from issue test: Add missing syncwithvalidationinterfacequeue in p2p_blockfilters by MarcoFalke
  61. DrahtBot cross-referenced this on Jun 23, 2021 from issue index, rpc: Coinstatsindex follow-ups by fjahr
  62. DrahtBot cross-referenced this on Jun 23, 2021 from issue Improve Indices on pruned nodes via prune blockers by fjahr
  63. DrahtBot cross-referenced this on Jun 23, 2021 from issue [net processing] Various tidying up of PeerManagerImpl ctor by jnewbery
  64. DrahtBot cross-referenced this on Jun 24, 2021 from issue Implement BIP 370 PSBTv2 by achow101
  65. DrahtBot cross-referenced this on Jun 24, 2021 from issue Default to NODE_WITNESS in nLocalServices by dhruv
  66. DrahtBot added the label Needs rebase on Jun 24, 2021
  67. MarcoFalke force-pushed on Jun 24, 2021
  68. DrahtBot removed the label Needs rebase on Jun 24, 2021
  69. DrahtBot cross-referenced this on Jun 29, 2021 from issue wallet: Make a tr() descriptor by default by achow101
  70. MarcoFalke force-pushed on Jul 7, 2021
  71. DrahtBot cross-referenced this on Jul 10, 2021 from issue test: wallet_listtransactions improvements (speedup, cleanup, logging) by theStack
  72. DrahtBot cross-referenced this on Jul 13, 2021 from issue test, refactor: add GetTransaction() coverage, improve rpc_rawtransaction by jonatack
  73. MarcoFalke force-pushed on Jul 14, 2021
  74. MarcoFalke force-pushed on Jul 21, 2021
  75. DrahtBot added the label Needs rebase on Jul 22, 2021
  76. mzumsande cross-referenced this on Jul 22, 2021 from issue CI timeout in test/functional/p2p_feefilter.py by jonatack
  77. MarcoFalke force-pushed on Jul 23, 2021
  78. DrahtBot removed the label Needs rebase on Jul 23, 2021
  79. jnewbery commented at 2:00 PM on July 23, 2021: member

    Concept ACK

  80. jnewbery commented at 12:40 PM on July 26, 2021: member

    What do you think about adding a generate() method to TestFramework that takes the index of the node that you want to generate on? It seems strange to pass a TestFramework function to the constructor of the TestNode.

  81. MarcoFalke commented at 1:01 PM on July 26, 2021: member

    That would require changing all calls to generate* and also disable TestNode::generate* to avoid races creeping in by accident. Happy to do that refactor if reviewers think it is worth it. I am mostly interested in the functional changes here.

  82. jnewbery commented at 3:39 PM on July 26, 2021: member

    Happy to do that refactor if reviewers think it is worth it.

    I think it's worth it, to avoid adding an implicit dependency from TestNode onto TestFramework.

  83. MarcoFalke commented at 9:32 AM on July 28, 2021: member

    Done in #22567. (Different pr, because the discussion here wasn't substantial, mostly GitHubs own spam, and I wanted to keep this version in case someone decides against #22567).

  84. MarcoFalke cross-referenced this on Jul 28, 2021 from issue test: Implicitly sync after generate* to preempt races and intermittent test failures by MarcoFalke
  85. DrahtBot added the label Needs rebase on Jul 28, 2021
  86. test: Pass default_sync_fun to TestNode constructor fa891ebded
  87. test: Create TestNode._rpc_dispatch method fac2235c5b
  88. test: Implicitly sync after generate*, unless opted out faa93599e1
  89. 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-
    fa77478d56
  90. MarcoFalke force-pushed on Jul 28, 2021
  91. DrahtBot removed the label Needs rebase on Jul 28, 2021
  92. DrahtBot cross-referenced this on Aug 18, 2021 from issue test: consolidate to f-strings (part 1) by fanquake
  93. DrahtBot added the label Needs rebase on Aug 18, 2021
  94. DrahtBot commented at 9:00 PM on August 18, 2021: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

    <sub>Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".</sub>

  95. MarcoFalke closed this on Aug 19, 2021

  96. MarcoFalke deleted the branch on Aug 19, 2021
  97. MarcoFalke cross-referenced this on Nov 8, 2021 from issue ci: Increase --timeout-factor in the native Windows CI task by hebasto
  98. MarcoFalke cross-referenced this on Jan 11, 2022 from issue test: MiniWallet: support default `from_node` for sending/creating txs by theStack
  99. bitcoin locked this on Aug 19, 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:54 UTC