diff --git a/include/ftl/protocol/self.hpp b/include/ftl/protocol/self.hpp index fcb697de5dff2c93e6066e9edebe1096f642c859..1eab3c9e44dcaf7c3509b02d4b0a9804938033d6 100644 --- a/include/ftl/protocol/self.hpp +++ b/include/ftl/protocol/self.hpp @@ -63,7 +63,7 @@ class Self { * Will block until all currently registered connnections have completed. * You should not use this, but rather use onConnect. */ - int waitConnections(); + int waitConnections(int seconds = 1); /** get peer pointer by peer UUID, returns nullptr if not found */ std::shared_ptr<ftl::protocol::Node> getNode(const ftl::UUID &pid) const; diff --git a/src/self.cpp b/src/self.cpp index d7e5e8f73176b9654ad68647704ebce311c0cb74..672a5d801743315430f124807c0a8332aaafbd2e 100644 --- a/src/self.cpp +++ b/src/self.cpp @@ -66,8 +66,8 @@ size_t Self::numberOfNodes() const { return universe_->numberOfPeers(); } -int Self::waitConnections() { - return universe_->waitConnections(); +int Self::waitConnections(int seconds) { + return universe_->waitConnections(seconds); } std::shared_ptr<ftl::protocol::Node> Self::getNode(const ftl::UUID &pid) const { diff --git a/src/universe.cpp b/src/universe.cpp index 3234336264415b63512c263059fce9284fe82b22..ddf25747c9191293f81a20902447231b98e81166 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -276,12 +276,12 @@ void Universe::unbind(const std::string &name) { disp_.unbind(name); } -int Universe::waitConnections() { +int Universe::waitConnections(int seconds) { SHARED_LOCK(net_mutex_, lk); auto peers = peers_; lk.unlock(); - return std::count_if(peers.begin(), peers.end(), [](const auto &p) { - return p && p->waitConnection(); + return std::count_if(peers.begin(), peers.end(), [seconds](const auto &p) { + return p && p->waitConnection(seconds); }); } diff --git a/src/universe.hpp b/src/universe.hpp index 1930d21e417f5fc193f137a91dd66ed9a9e858e1..f486b89de646805deb280ea077987e2b318f2ad1 100644 --- a/src/universe.hpp +++ b/src/universe.hpp @@ -99,7 +99,7 @@ public: * Will block until all currently registered connnections have completed. * You should not use this, but rather use onConnect. */ - int waitConnections(); + int waitConnections(int seconds = 1); /** get peer pointer by peer UUID, returns nullptr if not found */ PeerPtr getPeer(const ftl::UUID &pid) const; diff --git a/test/net_integration.cpp b/test/net_integration.cpp index 1ba570106a9bc9b4664f8a79bc0b4ca1adbde3f5..867d85f94f57849dc87810e0e56dfc2e1531989c 100644 --- a/test/net_integration.cpp +++ b/test/net_integration.cpp @@ -48,7 +48,7 @@ TEST_CASE("Listen and Connect", "[net]") { REQUIRE( p->waitConnection(5) ); - REQUIRE( self->waitConnections() == 1 ); + REQUIRE( self->waitConnections(5) == 1 ); REQUIRE( ftl::getSelf()->numberOfNodes() == 1); }