From f4119c6c988ea24a5218aa6bc67e57e47e051547 Mon Sep 17 00:00:00 2001 From: EthanHeilman Date: Wed, 18 May 2016 12:04:07 -0400 Subject: [PATCH 1/2] Remove non-determinism which is breaking net_tests #8069 --- src/test/net_tests.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 6debf6ac5..df1a4d2fb 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -17,6 +17,13 @@ class CAddrManSerializationMock : public CAddrMan { public: virtual void Serialize(CDataStream& s, int nType, int nVersionDummy) const = 0; + + //! Ensure that bucket placement is always the same for testing purposes. + void MakeDeterministic() + { + nKey.SetNull(); + seed_insecure_rand(true); + } }; class CAddrManUncorrupted : public CAddrManSerializationMock @@ -65,6 +72,7 @@ BOOST_FIXTURE_TEST_SUITE(net_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(caddrdb_read) { CAddrManUncorrupted addrmanUncorrupted; + addrmanUncorrupted.MakeDeterministic(); CService addr1 = CService("250.7.1.1", 8333); CService addr2 = CService("250.7.2.2", 9999); @@ -106,6 +114,7 @@ BOOST_AUTO_TEST_CASE(caddrdb_read) BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted) { CAddrManCorrupted addrmanCorrupted; + addrmanCorrupted.MakeDeterministic(); // Test that the de-serialization of corrupted addrman throws an exception. CDataStream ssPeers1 = AddrmanToStream(addrmanCorrupted); From 2a8b3589b5a6c0863012329ddb40e7d901decf0e Mon Sep 17 00:00:00 2001 From: Ethan Heilman Date: Wed, 18 May 2016 20:14:26 -0400 Subject: [PATCH 2/2] Fix typo adddrman to addrman as requested in #8070 --- src/test/net_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index df1a4d2fb..b38d61f33 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted) } catch (const std::exception& e) { exceptionThrown = true; } - // Even through de-serialization failed adddrman is not left in a clean state. + // Even through de-serialization failed addrman is not left in a clean state. BOOST_CHECK(addrman1.size() == 1); BOOST_CHECK(exceptionThrown);