Small correction with PIT (was correct, but now it is slightly better)
Another correction of scheduler test
diff --git a/model/sync-interest-table.cc b/model/sync-interest-table.cc
index 3a08fbd..703eded 100644
--- a/model/sync-interest-table.cc
+++ b/model/sync-interest-table.cc
@@ -32,7 +32,7 @@
SyncInterestTable::SyncInterestTable ()
{
- m_scheduler.schedule (posix_time::seconds (m_checkPeriod),
+ m_scheduler.schedule (posix_time::seconds (4),
bind (&SyncInterestTable::expireInterests, this),
0);
}
@@ -44,6 +44,7 @@
vector<string>
SyncInterestTable::fetchAll ()
{
+ expireInterests ();
recursive_mutex::scoped_lock lock (m_mutex);
vector<string> entries;
@@ -100,9 +101,10 @@
while (it != m_table.end())
{
time_t timestamp = it->second;
+ _LOG_DEBUG ("expireInterests (): " << timestamp << ", " << currentTime);
if (currentTime - timestamp > m_checkPeriod)
{
- it = m_table.erase(it);
+ it = m_table.erase (it);
count ++;
}
else
@@ -111,7 +113,7 @@
_LOG_DEBUG ("expireInterests (): expired " << count);
- m_scheduler.schedule (posix_time::seconds (m_checkPeriod),
+ m_scheduler.schedule (posix_time::seconds (4),
bind (&SyncInterestTable::expireInterests, this),
0);
}
diff --git a/test/test_pit.cc b/test/test_pit.cc
index bb85580..512f429 100644
--- a/test/test_pit.cc
+++ b/test/test_pit.cc
@@ -28,41 +28,48 @@
#include <boost/make_shared.hpp>
#include "../model/sync-interest-table.h"
+#include "../model/sync-log.h"
using namespace Sync;
using namespace std;
using namespace boost;
string sitToString(SyncInterestTable *sit) {
- vector<string> ent = sit->fetchAll();
- sort(ent.begin(), ent.end());
- string str = "";
- while(!ent.empty()){
- str += ent.back();
- ent.pop_back();
- }
- return str;
+ vector<string> ent = sit->fetchAll();
+ sort(ent.begin(), ent.end());
+ string str = "";
+ while(!ent.empty()){
+ str += ent.back();
+ ent.pop_back();
+ }
+ return str;
}
BOOST_AUTO_TEST_CASE (SyncInterestTableTest)
{
- SyncInterestTable sit;
- sit.insert("/ucla.edu/0");
- sit.insert("/ucla.edu/1");
- string str = sitToString(&sit);
- BOOST_CHECK_EQUAL(str, "/ucla.edu/1/ucla.edu/0");
+ INIT_LOGGERS ();
+ INIT_LOGGER ("Test.Pit");
- str = sitToString(&sit);
- BOOST_CHECK_EQUAL(str, "");
+ SyncInterestTable sit;
+ sit.insert("/ucla.edu/0");
+ sit.insert("/ucla.edu/1");
+ string str = sitToString(&sit);
+ BOOST_CHECK_EQUAL(str, "/ucla.edu/1/ucla.edu/0");
- sit.insert("/ucla.edu/0");
- sit.insert("/ucla.edu/1");
- sleep(2);
- sit.insert("/ucla.edu/0");
- sit.insert("/ucla.edu/2");
- sleep(3);
- str = sitToString(&sit);
- BOOST_CHECK_EQUAL(str, "/ucla.edu/2/ucla.edu/0");
+ str = sitToString(&sit);
+ BOOST_CHECK_EQUAL(str, "");
+
+ _LOG_DEBUG ("Adding 0 and 1");
+ sit.insert("/ucla.edu/0");
+ sit.insert("/ucla.edu/1");
+ sleep(2);
+ _LOG_DEBUG ("Adding 0 and 2");
+ sit.insert("/ucla.edu/0");
+ sit.insert("/ucla.edu/2");
+ sleep(3);
+ _LOG_DEBUG ("Checking");
+ str = sitToString(&sit);
+ BOOST_CHECK_EQUAL(str, "/ucla.edu/2/ucla.edu/0");
}
diff --git a/test/test_scheduler.cc b/test/test_scheduler.cc
index faf085b..62ed601 100644
--- a/test/test_scheduler.cc
+++ b/test/test_scheduler.cc
@@ -145,6 +145,7 @@
{
SyncLogic *logic = 0;
BOOST_CHECK_NO_THROW (logic = new SyncLogic ("/prefix", funcUpdate, funcRemove));
+ this_thread::sleep (posix_time::milliseconds (100));
Scheduler &scheduler = logic->getScheduler ();
BOOST_CHECK_EQUAL (scheduler.getEventsSize (), 1);