|
@ -57,6 +57,8 @@ BOOST_AUTO_TEST_CASE(topic) |
|
|
|
|
|
|
|
|
bool host1Ready = false; |
|
|
bool host1Ready = false; |
|
|
unsigned result = 0; |
|
|
unsigned result = 0; |
|
|
|
|
|
unsigned const step = 10; |
|
|
|
|
|
|
|
|
std::thread listener([&]() |
|
|
std::thread listener([&]() |
|
|
{ |
|
|
{ |
|
|
setThreadName("other"); |
|
|
setThreadName("other"); |
|
@ -86,21 +88,30 @@ BOOST_AUTO_TEST_CASE(topic) |
|
|
auto whost2 = host2.registerCapability(new WhisperHost()); |
|
|
auto whost2 = host2.registerCapability(new WhisperHost()); |
|
|
host2.start(); |
|
|
host2.start(); |
|
|
|
|
|
|
|
|
while (!host1.haveNetwork()) |
|
|
for (unsigned i = 0; i < 3000 && (!host1.haveNetwork() || !host2.haveNetwork()); i += step) |
|
|
this_thread::sleep_for(chrono::milliseconds(5)); |
|
|
this_thread::sleep_for(chrono::milliseconds(step)); |
|
|
|
|
|
|
|
|
|
|
|
BOOST_REQUIRE(host1.haveNetwork()); |
|
|
|
|
|
BOOST_REQUIRE(host2.haveNetwork()); |
|
|
|
|
|
|
|
|
host2.addNode(host1.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), port1, port1)); |
|
|
host2.addNode(host1.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), port1, port1)); |
|
|
|
|
|
|
|
|
// wait for nodes to connect
|
|
|
for (unsigned i = 0; i < 3000 && (!host1.peerCount() || !host2.peerCount()); i += step) |
|
|
this_thread::sleep_for(chrono::milliseconds(1000)); |
|
|
this_thread::sleep_for(chrono::milliseconds(step)); |
|
|
|
|
|
|
|
|
while (!host1Ready) |
|
|
BOOST_REQUIRE(host1.peerCount()); |
|
|
this_thread::sleep_for(chrono::milliseconds(10)); |
|
|
BOOST_REQUIRE(host2.peerCount()); |
|
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 3000 && !host1Ready; i += step) |
|
|
|
|
|
this_thread::sleep_for(chrono::milliseconds(step)); |
|
|
|
|
|
|
|
|
|
|
|
BOOST_REQUIRE(host1Ready); |
|
|
|
|
|
|
|
|
KeyPair us = KeyPair::create(); |
|
|
KeyPair us = KeyPair::create(); |
|
|
for (int i = 0; i < 10; ++i) |
|
|
for (int i = 0; i < 10; ++i) |
|
|
{ |
|
|
{ |
|
|
whost2->post(us.sec(), RLPStream().append(i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even")); |
|
|
whost2->post(us.sec(), RLPStream().append(i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even")); |
|
|
this_thread::sleep_for(chrono::milliseconds(250)); |
|
|
this_thread::sleep_for(chrono::milliseconds(50)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
listener.join(); |
|
|
listener.join(); |
|
|