tests: Fix issue with UnitTestClock-based event scheduling (extra sleep required)
Change-Id: I77f24f630697b6e41b3d935f0f1416e806516412
Refs: #2152
diff --git a/tests/unit-tests/security/test-certificate-cache.cpp b/tests/unit-tests/security/test-certificate-cache.cpp
index d98dd4a..54454e1 100644
--- a/tests/unit-tests/security/test-certificate-cache.cpp
+++ b/tests/unit-tests/security/test-certificate-cache.cpp
@@ -110,6 +110,7 @@
BOOST_FIXTURE_TEST_CASE(TtlRefresh, UnitTestTimeFixture)
{
cache->insertCertificate(cert1); // 500ms
+
io.poll();
BOOST_CHECK_EQUAL(cache->getSize(), 1);
@@ -119,6 +120,7 @@
// Refresh certificate in cache
cache->insertCertificate(cert1); // +500ms
+
io.poll();
BOOST_CHECK_EQUAL(cache->getSize(), 1);
@@ -140,6 +142,7 @@
BOOST_CHECK_EQUAL(cache->getSize(), 2);
cache->reset();
+
io.poll();
BOOST_CHECK_EQUAL(cache->getSize(), 0);
}
diff --git a/tests/unit-tests/util/test-time-unit-test-clock.cpp b/tests/unit-tests/util/test-time-unit-test-clock.cpp
index f9b121d..e43d4ed 100644
--- a/tests/unit-tests/util/test-time-unit-test-clock.cpp
+++ b/tests/unit-tests/util/test-time-unit-test-clock.cpp
@@ -24,6 +24,7 @@
#include "boost-test.hpp"
#include <boost/lexical_cast.hpp>
+#include <thread>
namespace ndn {
namespace tests {
@@ -54,7 +55,8 @@
{
BOOST_CHECK_EQUAL(time::system_clock::now().time_since_epoch(),
time::UnitTestClockTraits<time::system_clock>::getDefaultStartTime());
- usleep(1000000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
+
BOOST_CHECK_EQUAL(time::system_clock::now().time_since_epoch(),
time::UnitTestClockTraits<time::system_clock>::getDefaultStartTime());
@@ -109,7 +111,7 @@
BOOST_CHECK_EQUAL(time::steady_clock::now().time_since_epoch(),
time::steady_clock::duration::zero());
- usleep(1000000);
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
BOOST_CHECK_EQUAL(time::steady_clock::now().time_since_epoch(),
time::steady_clock::duration::zero());
@@ -138,13 +140,12 @@
bool hasFired = false;
scheduler.scheduleEvent(time::seconds(100), [&] { hasFired = true; });
- for (size_t i = 0; i < 10; ++i)
- io.poll();
+ io.poll();
BOOST_CHECK_EQUAL(hasFired, false);
steadyClock->advance(time::seconds(100));
- for (size_t i = 0; i < 10; ++i)
- io.poll();
+
+ io.poll();
BOOST_CHECK_EQUAL(hasFired, true);
}