rib: stop using the global scheduler

Change-Id: I0e205e2f1adf85be49b132b47791b27e4530697a
Refs: #4528
diff --git a/tests/rib/auto-prefix-propagator.t.cpp b/tests/rib/auto-prefix-propagator.t.cpp
index f8f12bc..f33c7ae 100644
--- a/tests/rib/auto-prefix-propagator.t.cpp
+++ b/tests/rib/auto-prefix-propagator.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -25,11 +25,11 @@
 
 #include "rib/auto-prefix-propagator.hpp"
 
+#include "tests/identity-management-fixture.hpp"
+
 #include <ndn-cxx/security/pib/pib.hpp>
 #include <ndn-cxx/util/dummy-client-face.hpp>
 
-#include "tests/identity-management-fixture.hpp"
-
 namespace nfd {
 namespace rib {
 namespace tests {
@@ -43,9 +43,10 @@
 {
 public:
   AutoPrefixPropagatorFixture()
-    : m_face(getGlobalIoService(), m_keyChain, {true, true})
+    : m_face(g_io, m_keyChain, {true, true})
+    , m_scheduler(g_io)
     , m_controller(m_face, m_keyChain)
-    , m_propagator(m_controller, m_keyChain, m_rib)
+    , m_propagator(m_controller, m_keyChain, m_scheduler, m_rib)
     , m_requests(m_face.sentInterests)
     , m_entries(m_propagator.m_propagatedEntries)
   {
@@ -174,6 +175,7 @@
 
 protected:
   ndn::util::DummyClientFace m_face;
+  ndn::util::Scheduler m_scheduler;
   ndn::nfd::Controller m_controller;
   Rib m_rib;
   AutoPrefixPropagator m_propagator;
@@ -226,7 +228,7 @@
     if (!insertEntryToRib("/test/A/app")) {
       return false;
     }
-    m_entries["/test/A"].succeed(nullptr);
+    m_entries["/test/A"].succeed(m_scheduler, nullptr);
     if (!eraseEntryFromRib("/test/A/app")) {
       return false;
     }
@@ -347,7 +349,7 @@
   BOOST_CHECK(m_requests.empty());
   BOOST_CHECK(m_entries.find("/test/B") == m_entries.end());
 
-  m_entries["/test/B/C"].succeed(nullptr);
+  m_entries["/test/B/C"].succeed(m_scheduler, nullptr);
   testRedoPropagation("/test/B"); // alternative identity has been propagated
   BOOST_CHECK(m_requests.empty());
   BOOST_CHECK(m_entries.find("/test/B") == m_entries.end());
@@ -367,7 +369,7 @@
   BOOST_REQUIRE(addIdentity("/test/A"));
 
   BOOST_REQUIRE(insertEntryToRib("/test/A/app")); // ensure afterInsertEntry signal emitted
-  m_entries["/test/A"].succeed(nullptr); // ensure there is a valid entry inserted
+  m_entries["/test/A"].succeed(m_scheduler, nullptr); // ensure there is a valid entry inserted
   BOOST_REQUIRE(eraseEntryFromRib("/test/A/app")); // ensure afterEraseEntry signal emitted
 
   BOOST_REQUIRE_EQUAL(m_requests.size(), 2);
@@ -383,7 +385,7 @@
   BOOST_REQUIRE(insertEntryToRib("/localhost/A/app"));
   BOOST_CHECK(m_requests.empty());
 
-  m_propagator.m_propagatedEntries["/localhost/A"].succeed(nullptr);
+  m_propagator.m_propagatedEntries["/localhost/A"].succeed(m_scheduler, nullptr);
   BOOST_REQUIRE(eraseEntryFromRib("/localhost/A/app"));
   BOOST_CHECK(m_requests.empty());
 }
@@ -398,7 +400,7 @@
   BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
   BOOST_CHECK(m_requests.empty());
 
-  m_entries["/test/A"].succeed(nullptr);
+  m_entries["/test/A"].succeed(m_scheduler, nullptr);
   BOOST_REQUIRE(eraseEntryFromRib("/test/A/app"));
   BOOST_CHECK(m_requests.empty());
 }
@@ -410,7 +412,7 @@
   BOOST_REQUIRE(insertEntryToRib("/test/A/app"));
   BOOST_CHECK(m_requests.empty());
 
-  m_entries["/test/A"].succeed(nullptr);
+  m_entries["/test/A"].succeed(m_scheduler, nullptr);
   BOOST_REQUIRE(eraseEntryFromRib("/test/A/app"));
   BOOST_CHECK(m_requests.empty());
 }
@@ -522,18 +524,18 @@
     advanceClocks(time::milliseconds(1));
   };
 
-  m_entries["/test/A"].succeed(nullptr);
+  m_entries["/test/A"].succeed(m_scheduler, nullptr);
   testAfterRibInsert("/test/A/app");
   BOOST_CHECK(m_requests.empty()); // no connectivity
   BOOST_CHECK(m_entries.find("/test/A") == m_entries.end()); // has been erased
 
   connectToHub();
-  m_entries["/test/A"].fail(nullptr);
+  m_entries["/test/A"].fail(m_scheduler, nullptr);
   testAfterRibInsert("/test/A/app");
   BOOST_CHECK(m_requests.empty()); // previous propagation has not succeeded
   BOOST_CHECK(m_entries.find("/test/A") == m_entries.end()); // has been erased
 
-  m_entries["/test/A"].succeed(nullptr);
+  m_entries["/test/A"].succeed(m_scheduler, nullptr);
   testAfterRibInsert("/test/A/app");
   BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
   BOOST_CHECK_EQUAL(checkRequest(0, "unregister", "/test/A"), CheckRequestResult::OK);
@@ -658,11 +660,11 @@
   testAfterRevokeSucceed("/test/A/app"); // in RELEASED state
   BOOST_CHECK(m_requests.empty());
 
-  m_entries["/test/A"].fail(nullptr); // in PROPAGATE_FAIL state
+  m_entries["/test/A"].fail(m_scheduler, nullptr); // in PROPAGATE_FAIL state
   testAfterRevokeSucceed("/test/A/app");
   BOOST_CHECK(m_requests.empty());
 
-  m_entries["/test/A"].succeed(nullptr); // in PROPAGATED state
+  m_entries["/test/A"].succeed(m_scheduler, nullptr); // in PROPAGATED state
   testAfterRevokeSucceed("/test/A/app");
   BOOST_REQUIRE_EQUAL(m_requests.size(), 1);
   BOOST_CHECK_EQUAL(checkRequest(0, "register", "/test/A"), CheckRequestResult::OK);
diff --git a/tests/rib/fib-updates-common.hpp b/tests/rib/fib-updates-common.hpp
index f063f5d..66b1c8e 100644
--- a/tests/rib/fib-updates-common.hpp
+++ b/tests/rib/fib-updates-common.hpp
@@ -27,6 +27,7 @@
 #define NFD_TESTS_RIB_FIB_UPDATES_COMMON_HPP
 
 #include "rib/fib-updater.hpp"
+
 #include "rib-test-common.hpp"
 #include "tests/identity-management-fixture.hpp"
 
@@ -63,7 +64,7 @@
 {
 public:
   FibUpdatesFixture()
-    : face(getGlobalIoService(), m_keyChain)
+    : face(g_io, m_keyChain)
     , controller(face, m_keyChain)
     , fibUpdater(rib, controller)
   {
diff --git a/tests/rib/propagated-entry.t.cpp b/tests/rib/propagated-entry.t.cpp
index fe43677..b03f153 100644
--- a/tests/rib/propagated-entry.t.cpp
+++ b/tests/rib/propagated-entry.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -55,16 +55,18 @@
 
 BOOST_AUTO_TEST_CASE(Succeed)
 {
+  ndn::util::Scheduler scheduler(g_io);
   PropagatedEntry entry;
-  entry.succeed(nullptr);
+  entry.succeed(scheduler, nullptr);
   BOOST_CHECK_EQUAL(PropagationStatus::PROPAGATED, entry.m_propagationStatus);
   BOOST_CHECK(entry.isPropagated());
 }
 
 BOOST_AUTO_TEST_CASE(Fail)
 {
+  ndn::util::Scheduler scheduler(g_io);
   PropagatedEntry entry;
-  entry.fail(nullptr);
+  entry.fail(scheduler, nullptr);
   BOOST_CHECK_EQUAL(PropagationStatus::PROPAGATE_FAIL, entry.m_propagationStatus);
   BOOST_CHECK(entry.isPropagateFail());
 }
diff --git a/tests/rib/readvertise/nfd-rib-readvertise-destination.t.cpp b/tests/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
index 75e8cfa..483f94a 100644
--- a/tests/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
+++ b/tests/rib/readvertise/nfd-rib-readvertise-destination.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -25,10 +25,11 @@
 
 #include "rib/readvertise/nfd-rib-readvertise-destination.hpp"
 
-#include "tests/test-common.hpp"
 #include "tests/identity-management-fixture.hpp"
-#include <ndn-cxx/util/dummy-client-face.hpp>
+#include "tests/test-common.hpp"
+
 #include <ndn-cxx/security/signing-info.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace nfd {
 namespace rib {
@@ -42,15 +43,12 @@
   NfdRibReadvertiseDestinationFixture()
     : nSuccessCallbacks(0)
     , nFailureCallbacks(0)
-    , face(getGlobalIoService(), m_keyChain, {true, false})
+    , face(g_io, m_keyChain, {true, false})
+    , scheduler(g_io)
     , controller(face, m_keyChain)
     , dest(controller, Name("/localhost/nlsr"), rib)
-    , successCallback([this] {
-        nSuccessCallbacks++;
-      })
-    , failureCallback([this] (const std::string& str) {
-        nFailureCallbacks++;
-      })
+    , successCallback([this] { nSuccessCallbacks++; })
+    , failureCallback([this] (const std::string&) { nFailureCallbacks++; })
   {
   }
 
@@ -60,6 +58,7 @@
 
 protected:
   ndn::util::DummyClientFace face;
+  ndn::util::Scheduler scheduler;
   ndn::nfd::Controller controller;
   Rib rib;
   NfdRibReadvertiseDestination dest;
@@ -123,7 +122,7 @@
 {
   Scenario scenario;
   Name prefix("/ndn/memphis/test");
-  ReadvertisedRoute rr(prefix);
+  ReadvertisedRoute rr(prefix, scheduler);
   const Name RIB_REGISTER_COMMAND_PREFIX("/localhost/nlsr/rib/register");
 
   dest.advertise(rr, successCallback, failureCallback);
@@ -201,7 +200,7 @@
 {
   Scenario scenario;
   Name prefix("/ndn/memphis/test");
-  ReadvertisedRoute rr(prefix);
+  ReadvertisedRoute rr(prefix, scheduler);
   const Name RIB_UNREGISTER_COMMAND_PREFIX("/localhost/nlsr/rib/unregister");
 
   dest.withdraw(rr, successCallback, failureCallback);
diff --git a/tests/rib/readvertise/readvertise.t.cpp b/tests/rib/readvertise/readvertise.t.cpp
index 5de7208..1ff0f85 100644
--- a/tests/rib/readvertise/readvertise.t.cpp
+++ b/tests/rib/readvertise/readvertise.t.cpp
@@ -27,7 +27,6 @@
 
 #include "tests/identity-management-fixture.hpp"
 
-#include <ndn-cxx/mgmt/nfd/controller.hpp>
 #include <ndn-cxx/util/dummy-client-face.hpp>
 #include <boost/range/adaptor/transformed.hpp>
 #include <boost/range/algorithm/copy.hpp>
@@ -115,14 +114,15 @@
 {
 public:
   ReadvertiseFixture()
-    : face(getGlobalIoService(), m_keyChain, {false, false})
-    , controller(face, m_keyChain)
+    : m_face(g_io, m_keyChain, {false, false})
+    , m_scheduler(g_io)
   {
     auto policyUnique = make_unique<DummyReadvertisePolicy>();
     policy = policyUnique.get();
     auto destinationUnique = make_unique<DummyReadvertiseDestination>();
     destination = destinationUnique.get();
-    readvertise.reset(new Readvertise(rib, std::move(policyUnique), std::move(destinationUnique)));
+    readvertise = make_unique<Readvertise>(m_rib, m_scheduler,
+                                           std::move(policyUnique), std::move(destinationUnique));
   }
 
   void
@@ -131,7 +131,7 @@
     Route route;
     route.faceId = faceId;
     route.origin = origin;
-    rib.insert(prefix, route);
+    m_rib.insert(prefix, route);
     this->advanceClocks(time::milliseconds(6));
   }
 
@@ -141,7 +141,7 @@
     Route route;
     route.faceId = faceId;
     route.origin = origin;
-    rib.erase(prefix, route);
+    m_rib.erase(prefix, route);
     this->advanceClocks(time::milliseconds(6));
   }
 
@@ -152,14 +152,15 @@
     this->advanceClocks(time::milliseconds(6));
   }
 
-public:
-  ndn::KeyChain m_keyChain;
-  ndn::util::DummyClientFace face;
-  ndn::nfd::Controller controller;
+protected:
   DummyReadvertisePolicy* policy;
   DummyReadvertiseDestination* destination;
-  Rib rib;
   unique_ptr<Readvertise> readvertise;
+
+private:
+  ndn::util::DummyClientFace m_face;
+  ndn::util::Scheduler m_scheduler;
+  Rib m_rib;
 };
 
 BOOST_AUTO_TEST_SUITE(Readvertise)
diff --git a/tests/rib/rib-manager.t.cpp b/tests/rib/rib-manager.t.cpp
index 8ccde7d..be59ca5 100644
--- a/tests/rib/rib-manager.t.cpp
+++ b/tests/rib/rib-manager.t.cpp
@@ -57,13 +57,13 @@
 {
 public:
   explicit
-  RibManagerFixture(const ConfigurationStatus& status,
-                    bool shouldClearRib)
+  RibManagerFixture(const ConfigurationStatus& status, bool shouldClearRib)
     : m_commands(m_face.sentInterests)
     , m_status(status)
+    , m_scheduler(g_io)
     , m_nfdController(m_face, m_keyChain)
     , m_fibUpdater(m_rib, m_nfdController)
-    , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher)
+    , m_manager(m_rib, m_face, m_keyChain, m_nfdController, m_dispatcher, m_scheduler)
   {
     m_rib.mockFibResponse = [] (const RibUpdateBatch& batch) {
       BOOST_CHECK(batch.begin() != batch.end());
@@ -208,6 +208,7 @@
   std::vector<Interest>& m_commands;
   ConfigurationStatus m_status;
 
+  ndn::util::Scheduler m_scheduler;
   ndn::nfd::Controller m_nfdController;
   Rib m_rib;
   FibUpdater m_fibUpdater;
diff --git a/tests/rib/sl-announce.t.cpp b/tests/rib/sl-announce.t.cpp
index c77b91a..c7808d3 100644
--- a/tests/rib/sl-announce.t.cpp
+++ b/tests/rib/sl-announce.t.cpp
@@ -26,6 +26,7 @@
 #include "rib/rib-manager.hpp"
 
 #include "tests/identity-management-fixture.hpp"
+
 #include <ndn-cxx/util/dummy-client-face.hpp>
 
 namespace nfd {
@@ -40,20 +41,21 @@
   using SlAnnounceResult = RibManager::SlAnnounceResult;
 
   RibManagerSlAnnounceFixture()
-    : m_face(getGlobalIoService(), m_keyChain)
+    : m_face(g_io, m_keyChain)
+    , m_scheduler(g_io)
     , m_nfdController(m_face, m_keyChain)
     , m_dispatcher(m_face, m_keyChain)
     , m_fibUpdater(rib, m_nfdController)
     , m_trustedSigner(m_keyChain.createIdentity("/trusted", ndn::RsaKeyParams()))
     , m_untrustedSigner(m_keyChain.createIdentity("/untrusted", ndn::RsaKeyParams()))
   {
-    rib.mockFibResponse = [] (const RibUpdateBatch& batch) { return true; };
+    rib.mockFibResponse = [] (const RibUpdateBatch&) { return true; };
     rib.wantMockFibResponseOnce = false;
 
     // Face, Controller, Dispatcher are irrelevant to SlAnnounce functions but required by
     // RibManager construction, so they are private. RibManager is a pointer to avoid code style
     // rule 1.4 violation.
-    manager = make_unique<RibManager>(rib, m_face, m_keyChain, m_nfdController, m_dispatcher);
+    manager = make_unique<RibManager>(rib, m_face, m_keyChain, m_nfdController, m_dispatcher, m_scheduler);
 
     loadTrustSchema();
   }
@@ -84,7 +86,7 @@
         result = res;
       });
 
-    getGlobalIoService().poll();
+    g_io.poll();
     BOOST_CHECK(result);
     return result.value_or(SlAnnounceResult::ERROR);
   }
@@ -101,7 +103,7 @@
         result = res;
       });
 
-    getGlobalIoService().poll();
+    g_io.poll();
     BOOST_CHECK(result);
     return result.value_or(SlAnnounceResult::ERROR);
   }
@@ -118,7 +120,7 @@
         result = found;
       });
 
-    getGlobalIoService().poll();
+    g_io.poll();
     BOOST_CHECK(result);
     return result.value_or(nullopt);
   }
@@ -161,6 +163,7 @@
 
 private:
   ndn::util::DummyClientFace m_face;
+  ndn::util::Scheduler m_scheduler;
   ndn::nfd::Controller m_nfdController;
   ndn::mgmt::Dispatcher m_dispatcher;
   FibUpdater m_fibUpdater;