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

addrmgr: fix intermittent addrmanager_internal_test bug #2131

Conversation

kcalvinalvin
Copy link
Collaborator

Sometimes the tests in the addrmanager_internal_test will fail with: "addrmanager_internal_test.go: expected to find 5 addresses, found 4"

This is because the generated address with randAddr() may not always generate an address that's routable. If the address is not routable, that address will not be added to the manager when calling AddAddress().

This bug is fixed by creating a new function routableRandAddr() that always creates a routable random address.

Sometimes the tests in the addrmanager_internal_test will fail with:
"addrmanager_internal_test.go: expected to find 5 addresses, found 4"

This is because the generated address with randAddr() may not always
generate an address that's routable. If the address is not routable,
that address will not be added to the manager when calling AddAddress().

This bug is fixed by creating a new function routableRandAddr() that
always creates a routable random address.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 8152603231

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage remained the same at 56.776%

Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 2 86.27%
Totals Coverage Status
Change from base Build 8117173129: 0.0%
Covered Lines: 29296
Relevant Lines: 51599

💛 - Coveralls

@kcalvinalvin
Copy link
Collaborator Author

To reproduce the bug, you can spam go test in the addrmgr package.

[I] calvin@nixos ~/b/b/addrmgr (master)> go test
--- FAIL: TestAddrManagerV1ToV2 (0.00s)
    addrmanager_internal_test.go:171: expected to find 5 adddresses, found 4
FAIL
exit status 1
FAIL    github.com/btcsuite/btcd/addrmgr        0.039s

This doesn't happen with this PR applied.

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice fix, LGTM 🎉

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🧩

@Roasbeef Roasbeef merged commit a4f4470 into btcsuite:master Mar 5, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants