File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -943,11 +943,13 @@ class CNode
943
943
void MaybeSetAddrName (const std::string& addrNameIn);
944
944
};
945
945
946
-
947
-
948
-
949
-
950
946
/* * Return a timestamp in the future (in microseconds) for exponentially distributed events. */
951
947
int64_t PoissonNextSend (int64_t now, int average_interval_seconds);
952
948
949
+ /* * Wrapper to return mockable type */
950
+ inline std::chrono::microseconds PoissonNextSend (std::chrono::microseconds now, std::chrono::seconds average_interval)
951
+ {
952
+ return std::chrono::microseconds{PoissonNextSend (now.count (), average_interval.count ())};
953
+ }
954
+
953
955
#endif // BITCOIN_NET_H
Original file line number Diff line number Diff line change @@ -303,5 +303,19 @@ BOOST_AUTO_TEST_CASE(LocalAddress_BasicLifecycle)
303
303
BOOST_CHECK_EQUAL (IsLocal (addr), false );
304
304
}
305
305
306
+ BOOST_AUTO_TEST_CASE (PoissonNextSend)
307
+ {
308
+ g_mock_deterministic_tests = true ;
309
+
310
+ int64_t now = 5000 ;
311
+ int average_interval_seconds = 600 ;
312
+
313
+ auto poisson = ::PoissonNextSend (now, average_interval_seconds);
314
+ std::chrono::microseconds poisson_chrono = ::PoissonNextSend (std::chrono::microseconds{now}, std::chrono::seconds{average_interval_seconds});
315
+
316
+ BOOST_CHECK_EQUAL (poisson, poisson_chrono.count ());
317
+
318
+ g_mock_deterministic_tests = false ;
319
+ }
306
320
307
321
BOOST_AUTO_TEST_SUITE_END ()
You can’t perform that action at this time.
0 commit comments