Browse Source

refactoring of topic test

cl-refactor
Vlad Gluhovsky 10 years ago
parent
commit
f75f4d8dc7
  1. 29
      test/libwhisper/whisperTopic.cpp

29
test/libwhisper/whisperTopic.cpp

@ -57,6 +57,8 @@ BOOST_AUTO_TEST_CASE(topic)
bool host1Ready = false;
unsigned result = 0;
unsigned const step = 10;
std::thread listener([&]()
{
setThreadName("other");
@ -85,22 +87,31 @@ BOOST_AUTO_TEST_CASE(topic)
host1.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost());
host2.start();
while (!host1.haveNetwork())
this_thread::sleep_for(chrono::milliseconds(5));
for (unsigned i = 0; i < 3000 && (!host1.haveNetwork() || !host2.haveNetwork()); i += step)
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));
// wait for nodes to connect
this_thread::sleep_for(chrono::milliseconds(1000));
while (!host1Ready)
this_thread::sleep_for(chrono::milliseconds(10));
for (unsigned i = 0; i < 3000 && (!host1.peerCount() || !host2.peerCount()); i += step)
this_thread::sleep_for(chrono::milliseconds(step));
BOOST_REQUIRE(host1.peerCount());
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();
for (int i = 0; i < 10; ++i)
{
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();

Loading…
Cancel
Save