diff --git a/test/libwhisper/whisperTopic.cpp b/test/libwhisper/whisperTopic.cpp index eda73a6ff..e8bd48946 100644 --- a/test/libwhisper/whisperTopic.cpp +++ b/test/libwhisper/whisperTopic.cpp @@ -325,39 +325,39 @@ BOOST_AUTO_TEST_CASE(topicAdvertising) while (!host1.haveNetwork()) this_thread::sleep_for(chrono::milliseconds(10)); + unsigned const step = 10; uint16_t port2 = 30318; Host host2("second", NetworkPreferences("127.0.0.1", port2, false)); host2.setIdealPeerCount(1); auto whost2 = host2.registerCapability(new WhisperHost()); unsigned w2 = whost2->installWatch(BuildTopicMask("test2")); - host2.start(); - while (!host2.haveNetwork()) - this_thread::sleep_for(chrono::milliseconds(10)); - host1.addNode(host2.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), port2, port2)); - while (!host1.haveNetwork()) - this_thread::sleep_for(chrono::milliseconds(10)); + for (unsigned i = 0; i < 3000 && (!host1.haveNetwork() || !host2.haveNetwork()); i += step) + this_thread::sleep_for(chrono::milliseconds(step)); - while (!host1.peerCount()) - this_thread::sleep_for(chrono::milliseconds(10)); + host1.addNode(host2.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), port2, port2)); - while (!host2.peerCount()) - 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)); std::vector, std::shared_ptr>> sessions; + TopicBloomFilterHash bf1; - for (int i = 0; i < 600; ++i) + for (int i = 0; i < 600 && !bf1; ++i) { sessions = whost1->peerSessions(); - if (!sessions.empty() && sessions.back().first->cap()->bloom()) - break; - else - this_thread::sleep_for(chrono::milliseconds(10)); + if (!sessions.empty()) + { + bf1 = sessions.back().first->cap()->bloom(); + if (bf1) + break; + } + + this_thread::sleep_for(chrono::milliseconds(10)); } BOOST_REQUIRE(sessions.size()); - TopicBloomFilterHash bf1 = sessions.back().first->cap()->bloom(); TopicBloomFilterHash bf2 = whost2->bloom(); BOOST_REQUIRE_EQUAL(bf1, bf2); BOOST_REQUIRE(bf1); @@ -368,16 +368,18 @@ BOOST_AUTO_TEST_CASE(topicAdvertising) for (int i = 0; i < 600; ++i) { sessions = whost2->peerSessions(); - if (!sessions.empty() && sessions.back().first->cap()->bloom()) - break; - else - this_thread::sleep_for(chrono::milliseconds(10)); + if (!sessions.empty()) + { + bf2 = sessions.back().first->cap()->bloom(); + if (bf2) + break; + } + + this_thread::sleep_for(chrono::milliseconds(10)); } BOOST_REQUIRE(sessions.size()); BOOST_REQUIRE_EQUAL(sessions.back().second->id, host1.id()); - - bf2 = sessions.back().first->cap()->bloom(); bf1 = whost1->bloom(); BOOST_REQUIRE_EQUAL(bf1, bf2); BOOST_REQUIRE(bf1);