btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.2k stars 2.36k forks source link

addrmgr: fix intermittent addrmanager_internal_test bug #2131

Closed kcalvinalvin closed 6 months ago

kcalvinalvin commented 6 months ago

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 commented 6 months ago

Pull Request Test Coverage Report for Build 8152603231

Details


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

💛 - Coveralls
kcalvinalvin commented 6 months ago

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.