Skip to content

Conversation

mzumsande
Copy link
Contributor

This PR (joint work with Amiti Uttarwar) changes the addrman unit tests such that they only use the public AddrMan interface:
This has the advantage that the tests are less implementation-dependent, i.e. it would be possible to rewrite the internal addrman implementation (as drafted here for using a multiindex) without having to adjust the tests.

This includes the following steps:

  • Adding a test-only function FindAddressEntry() to the public addrman interface which returns info about an address in addrman (e.g. bucket, position, whethe the address is in new or tried). Obviously we want to do this sparingly, but I think a single test-only function is ok (which could also be useful elsewhere, e.g. in fuzz tests).
  • Removal of the AddrManTest subclass which would reach into AddrMan's internals, using AddrMan instead
  • Removal of tests for internal helper functions that are not publicly exposed (these are still tested indirectly via the public functions calling them).
  • Additional tests for previously untested features such as multiplicity in the new tables, that can be tested with the help of FindAddressEntry().

All in all, this PR increases the unit test coverage of AddrMan by a bit.

@fanquake fanquake added the Tests label Dec 20, 2021
@jamesob
Copy link
Contributor

jamesob commented Dec 20, 2021

Concept ACK based on the description

@jnewbery
Copy link
Contributor

Strong concept ACK!

@glozow
Copy link
Member

glozow commented Dec 20, 2021

Concept ACK

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 21, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23807 (p2p: Remove GetAdjustedTime() from AddrMan by w0xlt)
  • #23373 (test: Parse command line arguments from unit and fuzz tests, make addrman consistency check ratio easier to change by vasild)
  • #22910 ([RFC] Encapsulate asmap in NetGroupManager by jnewbery)

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.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Looks great. Just minor comments inline.

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

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

tACK 250479a

@mzumsande mzumsande force-pushed the 202112_addrman_unit_tests_1 branch from 250479a to ce8196d Compare December 23, 2021 16:13
@mzumsande
Copy link
Contributor Author

Thanks for the reviews!
@jnewbery I believe I have addressed all your points in my push.

@mzumsande mzumsande force-pushed the 202112_addrman_unit_tests_1 branch from ce8196d to 5ecdaaf Compare December 23, 2021 17:00
Copy link
Member

@josibake josibake left a comment

Choose a reason for hiding this comment

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

tACK 5ecdaaf

This is great stuff! Rebased on master and ran the unit tests for each commit, everything looks good. I had one suggestion regarding Good(). I recompiled with my changes and everything still passes - feel free to ping me for a re-ack if you decide to take the suggestion

@jnewbery
Copy link
Contributor

utACK 5ecdaaf

I'd be happy to rereview if you wanted to address the three remaining review comments:

amitiuttarwar and others added 9 commits December 28, 2021 17:26
Co-Authored-By: Martin Zumsande <mzumsande@gmail.com>
By updating the test to use FindEntry, it no longer needs to reach into
AddrMan's internals (via GetBucketAndEntry) to assert expected
behaviors.
No need for a function, since it is only used once.

Co-Authored-By: Amiti Uttarwar <amiti@uttarwar.org>
Switches to AddrMan for tests that use no features of AddrManTest.
Also removes unusued AddrManTest variables

Co-Authored-By: Amiti Uttarwar <amiti@uttarwar.org>
The logic of these functions is already covered by existing unit tests
using publicly exposed functions of the interface.
Therefore, removing them does not decrease test coverage.
This covers Connected() which updates nTime, and SetServices()
which updates nServices
@mzumsande mzumsande force-pushed the 202112_addrman_unit_tests_1 branch from 5ecdaaf to 26046a1 Compare December 28, 2021 20:57
@mzumsande
Copy link
Contributor Author

I pushed an update that addresses the outstanding comments.

@josibake
Copy link
Member

reACK 26046a1

verified updates with git range-diff 5ecdaaf...26046a1

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

utACK 26046a1

Verified range-diff. Only changes are the suggestions in #23826 (comment).

@mzumsande mzumsande force-pushed the 202112_addrman_unit_tests_1 branch from 26046a1 to ea4c9fd Compare January 3, 2022 21:27
@mzumsande
Copy link
Contributor Author

Made another push, fixing a typo. Btw, this conflicts with #23373, which has been open a while longer but seems close - happy to rebase if that gets merged first.

@jnewbery
Copy link
Contributor

jnewbery commented Jan 4, 2022

ACK ea4c9fd

@josibake
Copy link
Member

josibake commented Jan 4, 2022

reACK ea4c9fd

verified with git range-diff

@fanquake fanquake merged commit 4ee7845 into bitcoin:master Jan 4, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 4, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jan 4, 2023
@mzumsande mzumsande deleted the 202112_addrman_unit_tests_1 branch January 16, 2023 18:47
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.

9 participants