@@ -53,6 +53,17 @@ namespace bpo = boost::program_options;
53
53
namespace fc {
54
54
extern std::unordered_map<std::string, logger> &get_logger_map ();
55
55
extern std::unordered_map<std::string, appender::ptr> &get_appender_map ();
56
+
57
+ /* * Waits for F() to return true before max_duration has passed.
58
+ */
59
+ template <typename Functor>
60
+ static void wait_for ( const fc::microseconds max_duration, const Functor&& f )
61
+ {
62
+ const auto start = fc::time_point::now ();
63
+ while ( !f () && fc::time_point::now () < start + max_duration )
64
+ fc::usleep (fc::milliseconds (100 ));
65
+ BOOST_REQUIRE ( f () );
66
+ }
56
67
}
57
68
58
69
BOOST_AUTO_TEST_CASE (load_configuration_options_test_config_logging_files_created)
@@ -234,7 +245,10 @@ BOOST_AUTO_TEST_CASE( two_node_network )
234
245
app1.initialize (app_dir.path (), cfg);
235
246
BOOST_TEST_MESSAGE ( " Starting app1 and waiting 500 ms" );
236
247
app1.startup ();
237
- fc::usleep (fc::milliseconds (500 ));
248
+ fc::wait_for ( fc::seconds (10 ), [&app1] () {
249
+ const auto status = app1.p2p_node ()->network_get_info ();
250
+ return status[" listening_on" ].as <fc::ip::endpoint>( 5 ).port () == 3939 ;
251
+ });
238
252
239
253
BOOST_TEST_MESSAGE ( " Creating and initializing app2" );
240
254
@@ -254,11 +268,7 @@ BOOST_AUTO_TEST_CASE( two_node_network )
254
268
BOOST_TEST_MESSAGE ( " Starting app2 and waiting for connection" );
255
269
app2.startup ();
256
270
257
- const auto start = fc::time_point::now ();
258
- do
259
- {
260
- fc::usleep (fc::milliseconds (200 ));
261
- } while ( app1.p2p_node ()->get_connection_count () < 1 && fc::time_point::now () < start + fc::seconds (5 ) );
271
+ fc::wait_for ( fc::seconds (10 ), [&app1] () { return app1.p2p_node ()->get_connection_count () > 0 ; } );
262
272
263
273
BOOST_REQUIRE_EQUAL (app1.p2p_node ()->get_connection_count (), 1u );
264
274
BOOST_CHECK_EQUAL (std::string (app1.p2p_node ()->get_connected_peers ().front ().host .get_address ()), " 127.0.0.1" );
0 commit comments