-
Notifications
You must be signed in to change notification settings - Fork 38.7k
test/refactor: reference p2p objects explicitly and remove confusing Test_Node.p2p property #19804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Heh, this one might be controversial. In theory it shouldn't be confusing if there is only exactly one p2p connection. If this pull gets Concept ACKs, that is fine. If not, it might be good to replace the |
|
@MarcoFalke indeed. You put this idea in my head 😂 but |
|
Yes, I remember that. It looks like that was in reply to a performance bottleneck. Is that still observable? |
|
@MarcoFalke I think the performance problems were addressed elsewhere (comment). We were talking about p2p_invalid_messages.py which has a lot of subtests that needed to wait for |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
Concept ACK is less clear than the explicit in terms of readability, in my opinion. Generally, if you have a function to create an object, the handle returned by that function should be the preferred way to access that object, and not some other implicit way. ( That said, I also agree to MarcoFalke that this might be controversial... if it doesn't get enough Concept ACKs, I'm also happy to ACK the variant with |
|
thanks for Concept ACK @theStack! Agreed that's more clear, I could also just apply the explicit I'll wait for more people to weigh in :) |
|
Yes, agreed that this seems controversial :) there was even discussion of this in the original PR: #11182 (comment) I don't have a strong preference for But I'm definitely in favor of |
|
That is true, I should have asked - @jnewbery how do you feel about this? |
I can see how The approach in this PR (removing the property entirely) seems fine to me. Concept ACK. |
|
Concept ACK And thanks for the motivation to learn about Are you also on MacOS? I had to install A few thoughts:
Here's a verify script that takes all of the above into account: |
@robot-dreams really good point about feature_versionbits_warning, thanks for catching that! I think the problem with using |
4d1179c to
fc804be
Compare
|
Oops, nice catch! I forgot to actually test the script myself 😅 It's a moot point at this point since your proposed change sounds better, but I think this would've worked (don't do the replace on lines that start with |
fc804be to
f1ccb4c
Compare
|
One day I will get the scripted-diff right on the first try... 😂 I figured 3 Concept ACKs was enough for me to put some work into this. Last push replaces |
robot-dreams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK f1ccb4cc9c4457bed2cc12ff9cedb30d56a31985 aside from nits
Thanks for cleaning this up! Going through and refactoring as you did must've been a nice opportunity to learn about each test / choose reasonable variable names :)
- Looked over change manually (note: I didn't think about the choice of variable names)
- Did
grepfor remaining occurrences ofp2p, made sure they were all as intended - Ran
test/functional/test_runner.py --extended, looks good except for a local failure that didn't look related to your change at all (feature_pruning.py) - Ran
commit-script-check.shlocally, looks good
maflcko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems odd to use a local reference and self.nodes[0].p2ps to access the same p2p connection
Use object returned from add_p2p_connection to refer to p2ps. Add a test class attribute if it needs to be used across many methods. Don't use the p2p property.
-BEGIN VERIFY SCRIPT- sed -i 's/\.p2p\./.p2ps[0]./g' test/functional/p2p_invalid_tx.py -END VERIFY SCRIPT-
f1ccb4c to
10d6150
Compare
|
Did a little more refactoring to make feature_block.py and feature_csv_activation.py more clear, addressed @MarcoFalke's comments. Just left p2p_invalid_tx.py for the scripted-diff since it seems to want a variable number of connections in |
|
utACK 10d6150 Thanks for improving the documentation as well! |
|
utACK 10d6150 |
guggero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK 10d6150.
I think the preferred way should indeed be to access the peers through the return value of add_p2p_connection whenever possible.
Perhaps we could make this PR less controversial by replacing all the index-based accesses where possible?
The two easiest examples would be:
- https://github.com/bitcoin/bitcoin/blob/master/test/functional/p2p_getdata.py#L45
- https://github.com/bitcoin/bitcoin/blob/master/test/functional/wallet_resendwallettransactions.py#L61
…and remove confusing Test_Node.p2p property 10d6150 [test] remove confusing p2p property (gzhao408) 549d30f scripted-diff: replace p2p with p2ps[0] in p2p_invalid_tx (gzhao408) 7a0de46 [doc] sample code for test framework p2p objects (gzhao408) 784f757 [refactor] clarify tests by referencing p2p objects directly (gzhao408) Pull request description: The `TestNode` has a `p2p` property which is an alias for `p2ps[0]`. I think this should be removed because it can be confusing and misleading (to both the test writer and reviewer), especially if a TestNode has multiple p2ps connected (which is the case for many tests). Another example is when a test has multiple subtests that connect 1 p2p and use the `p2p` property to reference it. If the subtests don't completely clean up after themselves, the subtests may affect one another. The best way to refer to a connected p2p is use the object returned by `add_p2p_connection` like this: ```py p2p_conn = node.add_p2p_connection(P2PInterface()) ``` A good example is [p2p_invalid_locator.py](https://github.com/bitcoin/bitcoin/blob/master/test/functional/p2p_invalid_locator.py), which cleans up after itself (waits in both `wait_for_disconnect` and in `disconnect_p2ps`) but wouldn't need so much complexity if it just referenced the connections directly. If there is only one connected, it's not really that tedious to just use `node.p2ps[0]` instead of `node.p2p` (and it can always be aliased inside the test itself). ACKs for top commit: robot-dreams: utACK 10d6150 jnewbery: utACK 10d6150 guggero: Concept ACK 10d6150. Tree-SHA512: 5965548929794ec660dae03467640cb2156d7d826cefd26d3a126472cbc2494b855c1d26bbb7b412281fbdc92b9798b9765a85c27bc1a97f7798f27f64db6f13
0fcaf73 test: use explicit p2p objects where available (Oliver Gugger) Pull request description: This is a follow-up patch to #19804 as suggested by MarcoFalke (#19804 (comment)). To make the intent of the tests easier to understand, we reference the p2p connection objects by their explicit names instead of the p2ps array. ACKs for top commit: theStack: ACK 0fcaf73 Tree-SHA512: 37db22185077beeadfa7245bb768b87d6b7a2cfb906c3c859ab92ec3d657122db7301777f0838e13dfc748f37303850144fb7553e6cb6c66903e304d6e10e659
Summary: Use object returned from add_p2p_connection to refer to p2ps. Add a test class attribute if it needs to be used across many methods. Don't use the p2p property. This is a backport of [[bitcoin/bitcoin#19804 | core#19804]] [1a/4] bitcoin/bitcoin@784f757 `abc*` test will be done separately. Test Plan: `ninja check-functional-extended` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D10320
Summary: Use object returned from add_p2p_connection to refer to p2ps, or use `node.p2ps[0]` when it needs to be used across many methods. Don't use the p2p property. For these files, this is best done by removing some unnecessary (and often overcomplicated) helper functions that can be replaced with a single line of code at the callsite. This is a backport of [[bitcoin/bitcoin#19804 | core#19804]] [1b/4] Test Plan: `ninja check-functional-extended` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D10321
Summary: This is a backport of [[bitcoin/bitcoin#19804 | core#19804]] [2/4] bitcoin/bitcoin@7a0de46 Test Plan: Proofreading Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D10322
Summary: This is a backport of [[bitcoin/bitcoin#19804 | core#19804]] [3/4] bitcoin/bitcoin@549d30f Test Plan: `test/functional/test_runner.py p2p_invalid_tx` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10324
Summary: This is a backport of [[bitcoin/bitcoin#19804 | core#19804]] [4/4] bitcoin/bitcoin@10d6150 Depends on D10320, D10321 and D10324 Test Plan: `ninja check-functional-extended` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D10325
The
TestNodehas ap2pproperty which is an alias forp2ps[0].I think this should be removed because it can be confusing and misleading (to both the test writer and reviewer), especially if a TestNode has multiple p2ps connected (which is the case for many tests).
Another example is when a test has multiple subtests that connect 1 p2p and use the
p2pproperty to reference it. If the subtests don't completely clean up after themselves, the subtests may affect one another.The best way to refer to a connected p2p is use the object returned by
add_p2p_connectionlike this:A good example is p2p_invalid_locator.py, which cleans up after itself (waits in both
wait_for_disconnectand indisconnect_p2ps) but wouldn't need so much complexity if it just referenced the connections directly.If there is only one connected, it's not really that tedious to just use
node.p2ps[0]instead ofnode.p2p(and it can always be aliased inside the test itself).