From f75f4d8dc77d00590af372a43b551660e2910b98 Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Mon, 27 Jul 2015 12:32:13 +0200 Subject: [PATCH] refactoring of topic test --- test/libwhisper/whisperTopic.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/test/libwhisper/whisperTopic.cpp b/test/libwhisper/whisperTopic.cpp index 6a58be045..eda73a6ff 100644 --- a/test/libwhisper/whisperTopic.cpp +++ b/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();