Skip to content

Conversation

@jnewbery
Copy link
Contributor

Some additional tidyups after the introduction of TestNode:

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK after quick glance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to explicitly set the network topology and initial state of the chain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faint agreement. It's easy to forget and start up 4 nodes when you only really need 2, for example. Not seeing the number of nodes makes that even harder to remember.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I've added a new commit that makes setting self.num_nodes mandatory. I haven't done the same for self.setup_clean_chain, since I think it makes more sense for that to have a default. If people feel strongly, it can be added in a future commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should raise RuntimeError('Not implemented') to enforce the docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - done

Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 06bde74f5ec8660975275f8594aee3a99064e327

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since self knows about self.options.tmpdir, and all calls to self.add_nodes passes self.options.tmpdir as dirname argument, it seems clean to just give it a default None and to set to self.options.tmpdir if None in add_nodes.
Or perhaps remove it entirely and always use self.options.tmpdir. Will it ever be anything else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Thanks! Added this in a new commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra_args=None, stderr=None maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestNode.start is only ever called by TestFramework.start_node, which has its own default for extra_args, so not strictly necessary, but I agree having a default here makes it clearer. Added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faint agreement. It's easy to forget and start up 4 nodes when you only really need 2, for example. Not seeing the number of nodes makes that even harder to remember.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it not just add_nodes(3, ..) here and then add/start/connect the fourth node below? That would remove a lot of necessary [self.nodes[0:3]] stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there's not currently a method to add a single node. The model after this PR is to add all nodes at the top of the test and then start/stop them as required during the test.

We could potentially add an add_node() method to be called during the test, but lets leave that for a future PR.

@jnewbery
Copy link
Contributor Author

@MarcoFalke @kallewoof - thanks for the review. I think I've responded to all your comments.

New commits pushed, and rebased on master.

@kallewoof
Copy link
Contributor

utACK df824a9

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought of not having any node started automatically? There are some tests that start with stop_node(0)..

So eachrun_test(self) the nodes are explicitly started, num_nodes can go away, even setup_clean_chain would be a start_node argument.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there are more setup_clean_chain = True so why not make it the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't made any changes to setup_clean_chain. See earlier comment:

I haven't done the same for self.setup_clean_chain, since I think it makes more sense for that to have a default. If people feel strongly, it can be added in a future commit.

Feel free to open a PR to change/remove the default if you think that's necessary. I don't think it's required for this PR.

@jnewbery
Copy link
Contributor Author

Thanks for the reivew @promag

Have you thought of not having any node started automatically? There are some tests that start with stop_node(0)

Tests that don't need their nodes to start should override the setup_network() or setup_nodes() methods. The vast majority of tests require nodes to be started at the top of the test, so that's the default.

setup_clean_chain would be a start_node argument.

setup_clean_chain is a property of the pre-mined chain. I don't think we should change it to be a property of the individual node (if you disagree please open a separate PR to demonstrate the change).

Copy link
Member

@maflcko maflcko Aug 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already done by setup_network.

Same for the line below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L41 stops node 1 (the encryptwallet RPC shuts down the node), so I believe all the p2p connections are lost and we need to reconnect the nodes after restarting node 1.

I've tested removing these two lines and the test fails (the next call to sync_all() fails)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed that the node shuts down.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK df824a92121eb68849e474e87098a441d4e52926

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are removing timewait=900 from all calls but the first. I assume this does not cause issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rpc_timeout is a property of TestNode set when instantiating the python object, not when starting up the bitcoind node.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derp. Fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not self.nodes[:3]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not self.nodes[:3]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changed in a refactoring commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Separates the act of creating a TestNode object from starting the node.
The test_framework now keeps track of its list of TestNodes, and test
writers can call start_node() and stop_node() without having to update
the self.nodes list.
Almost all test scripts currently need to override the __init__()
method. When they do that they need to call into super().__init__() as
the base class does some generic initialization.

This commit makes the base class __init__() call into set_test_params()
method. Individual test cases can override set_test_params() to setup
their test parameters.
@jnewbery
Copy link
Contributor Author

jnewbery commented Sep 1, 2017

Thanks @MarcoFalke . Review comments addressed.

@maflcko
Copy link
Member

maflcko commented Sep 1, 2017

re-utACK 7148b74

@maflcko maflcko merged commit 7148b74 into bitcoin:master Sep 1, 2017
maflcko pushed a commit that referenced this pull request Sep 1, 2017
7148b74 [tests] Functional tests must explicitly set num_nodes (John Newbery)
5448a14 [tests] don't override __init__() in individual tests (John Newbery)
6cf094a [tests] Avoid passing around member variables in test_framework (John Newbery)
36b6268 [tests] TestNode: separate add_node from start_node (John Newbery)
be2a2ab [tests] fix - use rpc_timeout as rpc timeout (John Newbery)

Pull request description:

  Some additional tidyups after the introduction of TestNode:

  - commit 1 makes TestNode use the correct rpc timeout. This should have been included in #11077
  - commit 2 separates `add_node()` from `start_node()` as originally discussed here: #10556 (comment) with @kallewoof . The test writer no longer needs to assign to `self.nodes` when starting/stopping nodes.
  - commit 3 adds a `set_test_params()` method, so individual tests don't need to override `__init__()` and call `super().__init__()`

Tree-SHA512: 0adb030623b96675b5c29e2890ce99ccd837ed05f721d0c91b35378c5ac01b6658174aac12f1f77402e1d38b61f39b3c43b4df85c96952565dde1cda05b0db84
sipa added a commit that referenced this pull request Sep 1, 2017
3918d93 [tests] fixups from set_test_params() (John Newbery)

Pull request description:

  #11121 had a silent merge conflict in `bitcoin_cli.py`. This fixes it.

  Also fixes a comment in `example_test.py`

Tree-SHA512: f22a645c51c9aeda005526338ad6f2ee07f2bab172847fc54f51fecf1c79e778970be61e5e637d4e0aba3a02e5aba0737b0b57f1bc11a514a1acd94c221b54d6
maflcko pushed a commit that referenced this pull request Sep 12, 2017
8fdb6f9 [tests] fixup dbcrash interaction with add_nodes() (John Newbery)

Pull request description:

  Another conflict with #11121. Apologies - this is entirely my fault. I didn't run the extended test suite after rebasing on master.

  @MarcoFalke @sdaftuar

Tree-SHA512: eefce1d1c63dc4a63c5e030a541e046ad4832e8a709c0a8aad40ffdc4712b2065486778b406dfa57cfd34e66db86064278ee3fea8f2c2afd2390772875e6fa3e
maflcko pushed a commit that referenced this pull request Sep 29, 2017
…nt future similar errors

f97ab35 qa: Fix bug introduced in p2p-segwit.py (Suhas Daftuar)
a782042 qa: Treat mininode p2p exceptions as fatal (Suhas Daftuar)

Pull request description:

  #11121 inadvertently broke the constructor for the `TestNode()` object in `p2p-segwit.py`, silently breaking at least one of the tests.

  Although the python code was raising exceptions due to a `TestNode()` object not existing (or having the right type), mininode was masking these from anyone running the test through the test_runner (like travis), because it catches all exceptions during message delivery and just prints a log message and continues.  Such "graceful" handling of errors is almost certainly something we don't want in our test suite, so the first commit here attempts to prevent that type of failure from ever being masked.

  The second commit fixes the particular bug in `p2p-segwit.py`.

Tree-SHA512: b6646e3cb1e05c35c28e8899c44104bf2e2d0384643ca87042ab7f6ec0960d89f5bf25a7b95bab6e32d401c20a6018226160500f6ddceb923e81ffb04adb4f2f
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
Separates the act of creating a TestNode object from starting the node.
The test_framework now keeps track of its list of TestNodes, and test
writers can call start_node() and stop_node() without having to update
the self.nodes list.

Github-Pull: bitcoin#11121
Rebased-From: 36b6268
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
Almost all test scripts currently need to override the __init__()
method. When they do that they need to call into super().__init__() as
the base class does some generic initialization.

This commit makes the base class __init__() call into set_test_params()
method. Individual test cases can override set_test_params() to setup
their test parameters.

Github-Pull: bitcoin#11121
Rebased-From: 5448a14
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
codablock pushed a commit to codablock/dash that referenced this pull request Sep 24, 2019
7148b74 [tests] Functional tests must explicitly set num_nodes (John Newbery)
5448a14 [tests] don't override __init__() in individual tests (John Newbery)
6cf094a [tests] Avoid passing around member variables in test_framework (John Newbery)
36b6268 [tests] TestNode: separate add_node from start_node (John Newbery)
be2a2ab [tests] fix - use rpc_timeout as rpc timeout (John Newbery)

Pull request description:

  Some additional tidyups after the introduction of TestNode:

  - commit 1 makes TestNode use the correct rpc timeout. This should have been included in bitcoin#11077
  - commit 2 separates `add_node()` from `start_node()` as originally discussed here: bitcoin#10556 (comment) with @kallewoof . The test writer no longer needs to assign to `self.nodes` when starting/stopping nodes.
  - commit 3 adds a `set_test_params()` method, so individual tests don't need to override `__init__()` and call `super().__init__()`

Tree-SHA512: 0adb030623b96675b5c29e2890ce99ccd837ed05f721d0c91b35378c5ac01b6658174aac12f1f77402e1d38b61f39b3c43b4df85c96952565dde1cda05b0db84
codablock pushed a commit to codablock/dash that referenced this pull request Sep 24, 2019
3918d93 [tests] fixups from set_test_params() (John Newbery)

Pull request description:

  bitcoin#11121 had a silent merge conflict in `bitcoin_cli.py`. This fixes it.

  Also fixes a comment in `example_test.py`

Tree-SHA512: f22a645c51c9aeda005526338ad6f2ee07f2bab172847fc54f51fecf1c79e778970be61e5e637d4e0aba3a02e5aba0737b0b57f1bc11a514a1acd94c221b54d6
codablock pushed a commit to codablock/dash that referenced this pull request Sep 24, 2019
8fdb6f9 [tests] fixup dbcrash interaction with add_nodes() (John Newbery)

Pull request description:

  Another conflict with bitcoin#11121. Apologies - this is entirely my fault. I didn't run the extended test suite after rebasing on master.

  @MarcoFalke @sdaftuar

Tree-SHA512: eefce1d1c63dc4a63c5e030a541e046ad4832e8a709c0a8aad40ffdc4712b2065486778b406dfa57cfd34e66db86064278ee3fea8f2c2afd2390772875e6fa3e
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants