Skip to content
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

Optimize test_wallet_sync #11103

Merged
merged 4 commits into from
Apr 20, 2022
Merged

Optimize test_wallet_sync #11103

merged 4 commits into from
Apr 20, 2022

Conversation

mariano54
Copy link
Contributor

@mariano54 mariano54 commented Apr 8, 2022

Running every test twice with two modes is wasteful, we can share a lot of the slow stuff

@mariano54 mariano54 requested a review from altendky April 8, 2022 18:01
@mariano54 mariano54 added the ready_to_merge Submitter and reviewers think this is ready label Apr 8, 2022
Copy link
Contributor

@altendky altendky left a comment

Choose a reason for hiding this comment

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

Thanks for the extra work to retain coverage of the two sync modes while reducing runtime.

tests/wallet/sync/test_wallet_sync.py Show resolved Hide resolved
Comment on lines +82 to +84
for i in range(20):
# Tests a reorg with the wallet
ph = both_phs[i % 2]
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal either way, but figured I'd offer this.

https://docs.python.org/3.10/library/itertools.html#itertools.cycle

Suggested change
for i in range(20):
# Tests a reorg with the wallet
ph = both_phs[i % 2]
for i, ph in zip(range(20), itertools.cycle(both_phs)):
# Tests a reorg with the wallet

Copy link
Contributor Author

@mariano54 mariano54 Apr 9, 2022

Choose a reason for hiding this comment

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

Thank you, but that is much more complicated imo

Copy link
Contributor

Choose a reason for hiding this comment

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

It is true that modulus is a common programming idiom. How about this? We really don't care about the range nor the modulus of the iteration.

Suggested change
for i in range(20):
# Tests a reorg with the wallet
ph = both_phs[i % 2]
for ph in both_phs * 10:
# Tests a reorg with the wallet

I don't mean to badger about this but I realized this much simpler form than my last suggestion. Feel free to mark this resolved.

)
for i in range(1000, len(new_blocks)):
for i in range(base_num_blocks + 20, len(new_blocks)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Am I reading this right?

Suggested change
for i in range(base_num_blocks + 20, len(new_blocks)):
for i in range(len(all_blocks), len(new_blocks)):

tests/wallet/sync/test_wallet_sync.py Outdated Show resolved Hide resolved

# Insert 400 blocks
for block in default_400_blocks:
await full_node_api.full_node.respond_block(full_node_protocol.RespondBlock(block))

# Farm few more with reward
for i in range(0, num_blocks - 1):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why - 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test was testing only one wallet, but farming rewards take 1 block to get confirmed. So here the first wallet needs less rewards because all of them will get confirmed, in the second one, the last one will not get confirmed

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation. I think I might generally prefer to make sure all the rewards get processed rather than finishing the test with unconfirmed transactions and off-by-one compensations.

But, you can go ahead and resolve this conversation once you've read my comment. No action requested.

@mariano54 mariano54 removed the ready_to_merge Submitter and reviewers think this is ready label Apr 9, 2022
@mariano54 mariano54 requested a review from altendky April 9, 2022 14:40
@mariano54 mariano54 added the ready_to_merge Submitter and reviewers think this is ready label Apr 9, 2022
@wjblanke wjblanke merged commit f7e9e83 into main Apr 20, 2022
@wjblanke wjblanke deleted the ms.wallet_sync_test branch April 20, 2022 18:13
emlowe pushed a commit that referenced this pull request Apr 21, 2022
* Optimize test_wallet_sync

* Update tests/wallet/sync/test_wallet_sync.py

Co-authored-by: Kyle Altendorf <sda@fstab.net>

* Fix test

Co-authored-by: Kyle Altendorf <sda@fstab.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready_to_merge Submitter and reviewers think this is ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants