From e33b00386200fb5ed9b803f0823dd47332549e64 Mon Sep 17 00:00:00 2001 From: subtly Date: Sun, 5 Apr 2015 17:01:57 +0200 Subject: [PATCH 1/4] fix first whisper test --- whisperTopic.cpp | 75 ++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/whisperTopic.cpp b/whisperTopic.cpp index 0ea681b67..f2aa818ee 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -32,33 +32,27 @@ using namespace dev::shh; BOOST_AUTO_TEST_SUITE(whisper) -#if ALEX_HASH_FIXED_NETWORKING BOOST_AUTO_TEST_CASE(topic) { cnote << "Testing Whisper..."; auto oldLogVerbosity = g_logVerbosity; - g_logVerbosity = 0; + g_logVerbosity = 11; - Host host1("Test", NetworkPreferences(30303, "127.0.0.1", false, true)); + Host host1("Test", NetworkPreferences("127.0.0.1", 30303, false)); + host1.setIdealPeerCount(1); auto whost1 = host1.registerCapability(new WhisperHost()); host1.start(); - while (!host1.isStarted()) - this_thread::sleep_for(chrono::milliseconds(2)); - - bool started = false; + bool host1Ready = false; unsigned result = 0; std::thread listener([&]() { setThreadName("other"); - started = true; - + /// Only interested in odd packets auto w = whost1->installWatch(BuildTopicMask("odd")); - - started = true; + host1Ready = true; set received; - for (int iterout = 0, last = 0; iterout < 200 && last < 81; ++iterout) { for (auto i: whost1->checkWatch(w)) @@ -76,21 +70,21 @@ BOOST_AUTO_TEST_CASE(topic) }); - Host host2("Test", NetworkPreferences(30300, "127.0.0.1", false, true)); + Host host2("Test", NetworkPreferences("127.0.0.1", 30300, false)); + host1.setIdealPeerCount(1); auto whost2 = host2.registerCapability(new WhisperHost()); host2.start(); + + while (!host1.haveNetwork()) + this_thread::sleep_for(chrono::milliseconds(5)); + host2.addNode(host1.id(), bi::address::from_string("127.0.0.1"), 30303, 30303); - while (!host2.isStarted()) - this_thread::sleep_for(chrono::milliseconds(2)); - - this_thread::sleep_for(chrono::milliseconds(100)); - host2.addNode(host1.id(), "127.0.0.1", 30303, 30303); - - this_thread::sleep_for(chrono::milliseconds(500)); - - while (!started) - this_thread::sleep_for(chrono::milliseconds(2)); - + // wait for nodes to connect + this_thread::sleep_for(chrono::milliseconds(1000)); + + while (!host1Ready) + this_thread::sleep_for(chrono::milliseconds(10)); + KeyPair us = KeyPair::create(); for (int i = 0; i < 10; ++i) { @@ -104,6 +98,7 @@ BOOST_AUTO_TEST_CASE(topic) BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81); } +#if ALEX_HASH_FIXED_NETWORKING BOOST_AUTO_TEST_CASE(forwarding) { cnote << "Testing Whisper forwarding..."; @@ -111,11 +106,11 @@ BOOST_AUTO_TEST_CASE(forwarding) g_logVerbosity = 0; // Host must be configured not to share peers. - Host host1("Listner", NetworkPreferences(30303, "", false, true)); + Host host1("Listner", NetworkPreferences("127.0.0.1", 30303, false)); host1.setIdealPeerCount(0); auto whost1 = host1.registerCapability(new WhisperHost()); host1.start(); - while (!host1.isStarted()) + while (!host1.haveNetwork()) this_thread::sleep_for(chrono::milliseconds(2)); unsigned result = 0; @@ -146,11 +141,11 @@ BOOST_AUTO_TEST_CASE(forwarding) // Host must be configured not to share peers. - Host host2("Forwarder", NetworkPreferences(30305, "", false, true)); + Host host2("Forwarder", NetworkPreferences("127.0.0.1", 30305, false)); host2.setIdealPeerCount(1); auto whost2 = host2.registerCapability(new WhisperHost()); host2.start(); - while (!host2.isStarted()) + while (!host2.haveNetwork()) this_thread::sleep_for(chrono::milliseconds(2)); Public fwderid; @@ -163,7 +158,7 @@ BOOST_AUTO_TEST_CASE(forwarding) this_thread::sleep_for(chrono::milliseconds(50)); this_thread::sleep_for(chrono::milliseconds(500)); - host2.addNode(host1.id(), "127.0.0.1", 30303, 30303); + host2.addNode(host1.id(), bi::address::from_string("127.0.0.1"), 30303, 30303); startedForwarder = true; @@ -184,12 +179,12 @@ BOOST_AUTO_TEST_CASE(forwarding) while (!startedForwarder) this_thread::sleep_for(chrono::milliseconds(50)); - Host ph("Sender", NetworkPreferences(30300, "", false, true)); + Host ph("Sender", NetworkPreferences("127.0.0.1", 30300, false)); ph.setIdealPeerCount(1); shared_ptr wh = ph.registerCapability(new WhisperHost()); ph.start(); - ph.addNode(host2.id(), "127.0.0.1", 30305, 30305); - while (!ph.isStarted()) + ph.addNode(host2.id(), bi::address::from_string("127.0.0.1"), 30305, 30305); + while (!ph.haveNetwork()) this_thread::sleep_for(chrono::milliseconds(10)); KeyPair us = KeyPair::create(); @@ -214,11 +209,11 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) bool done = false; // Host must be configured not to share peers. - Host host1("Forwarder", NetworkPreferences(30305, "", false, true)); + Host host1("Forwarder", NetworkPreferences("127.0.0.1", 30305, false)); host1.setIdealPeerCount(1); auto whost1 = host1.registerCapability(new WhisperHost()); host1.start(); - while (!host1.isStarted()) + while (!host1.haveNetwork()) this_thread::sleep_for(chrono::milliseconds(2)); bool startedForwarder = false; @@ -249,13 +244,13 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) this_thread::sleep_for(chrono::milliseconds(2)); { - Host host2("Sender", NetworkPreferences(30300, "", false, true)); + Host host2("Sender", NetworkPreferences("127.0.0.1", 30300, false)); host2.setIdealPeerCount(1); shared_ptr whost2 = host2.registerCapability(new WhisperHost()); host2.start(); - while (!host2.isStarted()) + while (!host2.haveNetwork()) this_thread::sleep_for(chrono::milliseconds(2)); - host2.addNode(host1.id(), "127.0.0.1", 30305, 30305); + host2.addNode(host1.id(), bi::address::from_string("127.0.0.1"), 30305, 30305); while (!host2.peerCount()) this_thread::sleep_for(chrono::milliseconds(5)); @@ -266,13 +261,13 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) } { - Host ph("Listener", NetworkPreferences(30300, "", false, true)); + Host ph("Listener", NetworkPreferences("127.0.0.1", 30300, false)); ph.setIdealPeerCount(1); shared_ptr wh = ph.registerCapability(new WhisperHost()); ph.start(); - while (!ph.isStarted()) + while (!ph.haveNetwork()) this_thread::sleep_for(chrono::milliseconds(2)); - ph.addNode(host1.id(), "127.0.0.1", 30305, 30305); + ph.addNode(host1.id(), bi::address::from_string("127.0.0.1"), 30305, 30305); /// Only interested in odd packets auto w = wh->installWatch(BuildTopicMask("test")); From 4597ae7260752ac4bddfe7eb0737088d4fcb3ed7 Mon Sep 17 00:00:00 2001 From: subtly Date: Sun, 5 Apr 2015 17:10:29 +0200 Subject: [PATCH 2/4] reenable whisper tests --- whisperTopic.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/whisperTopic.cpp b/whisperTopic.cpp index f2aa818ee..b43ba708e 100644 --- a/whisperTopic.cpp +++ b/whisperTopic.cpp @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(topic) { cnote << "Testing Whisper..."; auto oldLogVerbosity = g_logVerbosity; - g_logVerbosity = 11; + g_logVerbosity = 0; Host host1("Test", NetworkPreferences("127.0.0.1", 30303, false)); host1.setIdealPeerCount(1); @@ -98,7 +98,6 @@ BOOST_AUTO_TEST_CASE(topic) BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81); } -#if ALEX_HASH_FIXED_NETWORKING BOOST_AUTO_TEST_CASE(forwarding) { cnote << "Testing Whisper forwarding..."; @@ -291,6 +290,5 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) BOOST_REQUIRE_EQUAL(result, 1); } -#endif BOOST_AUTO_TEST_SUITE_END() From 235cad6f19d7b40f42590fe5e20689d7ae9e8d54 Mon Sep 17 00:00:00 2001 From: subtly Date: Fri, 8 May 2015 18:19:31 +0200 Subject: [PATCH 3/4] update whisper test to use fixture for new network code, to allow private addresses and encapsulate host/port information in NodeIPEndpoint. From 8c17234dbb78faba8c2aa68e2958b13b23c90f76 Mon Sep 17 00:00:00 2001 From: subtly Date: Thu, 4 Jun 2015 17:27:35 +0200 Subject: [PATCH 4/4] update whisper tests