Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Adds unittests for CAddrMan and CAddrinfo, removes source of non-determinism. #7212
Details on GetRandInt Wrapper
To allow for deterministic tests of the select method in CAddrMan we wrap the GetRandInt function with a method RandomInt which can be overridden in a test class CAddrManTest. The RandomInt wrapper name was used so that it would not be a prefix substring of GetRandInt to avoid find and replace mistakes. Changes to random number generators as always a concern, this approach presents no risks because only subclasses of addrman can redirect calls to GetRandInt.
IPv4 IPv6 confusion
@paveljanik Almost none of these changes are unnecessary, they significantly increase the readability, accuracy and the coverage of these tests (as explained in prior comments). The fact that it appears the changes should not have an impact when in fact that do, is evidence against leaving the tests as is.
Update: Since the last push deleted both of our comments, I am rewritten my explanation in the pull request description.
I have rewritten my commit to so that CNetAddr no longer takes a port number.
I have keep my changes where I break the port out when using the CService constructor. That is:
CService("250.2.2.2:8333") changed to CService("250.2.2.2", 8333)
@paveljanik is correct that these changes are unnecessary, however given that the fix for the CNetAddr issue involves overhauling the tests anyways lets make them more readable as well. That being said, I am willing to change them back if anyone feels strongly about it.
referenced this pull request
Jan 4, 2016
added a commit
this pull request
Jan 4, 2016
Added a test for GetAddr.
@laanwj Are there any changes I need to make to get this accepted with the next ~30 days? I have some bug fixes which I'm writing right now which I'm pushing in early March/Late Feb. The fixes build on these tests, but I'd like to do them in a separate pull request since its pretty different from this pull request.
Edit: oops, had been confusing your issues, that is #7291