[tests] Demostration/concept: Add a TestNode class to test_Framework.py #10082

pull jnewbery wants to merge 11 commits into bitcoin:master from jnewbery:refactor_utils_py changing 64 files +638 −605
  1. jnewbery commented at 4:53 am on March 26, 2017: member

    This PR is too large for review and will need continually rebasing. This PR tracks the individual tasks to introduce a TestNode class. The individual commits are in separate PRs

    Tasks:

    • #10171 Add initialize chain / start node / stop node methods to TestFramework. Initially these are wrapper methods which call into the functions in util.py (not disruptive - only touches test_framework files)
    • #10359 Update individual test cases to call TestFramework.start_node() etc (disruptive - touches all test cases, so will require rebases for open PRs)
    • #10556 Change TestFramework start/stop methods to contain the logic and remove the functions from util.py. Also move the stateful port and coverage functions into TestFramework (not disruptive - only touches test_framework files)
    • #10711 Add the TestNode class (not disruptive - only touches test_framework files)
    • #11182 Add p2p connections into the TestNode class (not disruptive - only touches test_framework files)
    • #11182 Update individual test cases to use TestNode class (marginally disruptive - does not need to be done all at once)

    This PR adds a TestNode class to the test_framework.py module. The goals for this are:

    1. Present a clean interface to the test writer

    The test writer should be able to set up a desired network topology and not have to think too hard about how to start bitcoind instances and setup RPC/P2P connections to them.

    To create a node with an RPC and a P2P connection, tests currently look something like this:

    0        self.nodes = []
    1        self.nodes.append(start_node(0, self.options.tmpdir))
    2        node0 = SingleNodeConnCB()
    3        connections = []
    4        connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], node0))
    5        node0.add_connection(connections[0])
    6        NetworkThread().start()  # Start up network handling in another thread
    7        node0.wait_for_verack()
    

    After this PR, that should be more like this:

    0        self.num_nodes = 1
    1        self.start_nodes()
    2        self.nodes[0].add_p2p_connection()
    

    the tester now has a TestNode instance self.nodes[0] which he/she can use to send RPC commands, send P2P messages and register callbacks for received P2P messages.

    1. Remove global state from utils.py

    There are currently several global state variables in utils.py (COVERAGE_DIR, PortSeed and bitcoind_processes). Having global state variables in the utils module is bad practice and makes importing from utils quite brittle. It also makes it difficult to add functionality to the test framework without inadvertently breaking something.

  2. fanquake added the label Tests on Mar 26, 2017
  3. NicolasDorier commented at 1:41 pm on March 26, 2017: contributor
    Very nice, concept ACK.
  4. move initialize_chain() and initialize_chain_clean() to be methods of BitcoinTestFramework 2012ecc9cf
  5. Add stop_nodes() method to BitcoinTestFramework 490721fcfa
  6. add start_node() and start_nodes() methods to BitcoinTestFramework 52054c4d13
  7. Reorganize BitcoinTestFunction class 74b3e8b19a
  8. Use self.st{art,op}_node{,s}() method in BitcoinTestFramework 2177394abf
  9. Move global state to BitcoinTestFramework
    This commit moves functions st{art,op}_nodes{,s}() functions
    and bitcoind_processes and coverage variables into BitcoinTestFramework
    8abb09a2d3
  10. Add default values to start_node() and start_nodes()
    This commit adds default values to the num_nodes and dirname arguments
    in start_node() and start_nodes(). All calls to these methods used
    self.options.tmpdir and most used self.num_nodes for these values.
    Having those as the defaults simplifies the interface.
    
    This commit also changes sequential start_node() calls to a single
    start_nodes() call where possible. When start_nodes() is updated to
    start nodes in parallel this will make test startup faster.
    acf924c6aa
  11. Add TestNode class
    This commit adds a TestNode class to test_framework.py. This class is
    responsible for all state related to a bitcoind node under test. It
    stores local state, is responsible for tracking the bitcoind process and
    delegates unrecognised messages to the RPC connection.
    b5aa1097c9
  12. jnewbery renamed this:
    [tests] Add a TestNode class to test_Framework.py
    [tests] Demostration/concept: Add a TestNode class to test_Framework.py
    on Mar 30, 2017
  13. Add p2p connection to TestNode 606cc54915
  14. Use TestNode.p2p in assumevalid.py 75e8514922
  15. Use TestNode.p2p in maxuploadtarget.py 328763ab3d
  16. jnewbery force-pushed on Apr 8, 2017
  17. MarcoFalke referenced this in commit 85aec87b11 on Aug 15, 2017
  18. MarcoFalke commented at 9:23 am on September 2, 2017: member
    @jnewbery Should this be kept open?
  19. jnewbery commented at 3:01 pm on September 4, 2017: member
    Perhaps if/when #11182 is merged we can close this? (or we can close now if you feel strongly)
  20. MarcoFalke commented at 7:28 pm on September 5, 2017: member
    Going to close this. People interested should focus on reviewing the last bit, i.e. #11182.
  21. MarcoFalke closed this on Sep 5, 2017

  22. MarcoFalke referenced this in commit f7388e93d3 on Nov 8, 2017
  23. PastaPastaPasta referenced this in commit 74ab3e9dae on Sep 19, 2019
  24. PastaPastaPasta referenced this in commit ee44950e7d on Sep 23, 2019
  25. PastaPastaPasta referenced this in commit e221b458ca on Sep 24, 2019
  26. codablock referenced this in commit f55da3aa54 on Sep 24, 2019
  27. codablock referenced this in commit 65487ade38 on Sep 30, 2019
  28. codablock referenced this in commit 0f17abaa29 on Sep 30, 2019
  29. codablock referenced this in commit ec1d2b6722 on Oct 2, 2019
  30. codablock referenced this in commit 7b9dd03e27 on Oct 2, 2019
  31. UdjinM6 referenced this in commit c9a8bac497 on Oct 3, 2019
  32. codablock referenced this in commit 7c163b1ffd on Oct 3, 2019
  33. barrystyle referenced this in commit 1195059eac on Jan 22, 2020
  34. barrystyle referenced this in commit fca03b56ee on Jan 22, 2020
  35. DrahtBot locked this on Sep 8, 2021

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: 2024-07-05 19:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me