rib: change FIB mocking mechanism
Previously, RIB test suites mock FIB updates by invoking RibManager
or Rib's private methods from a callback. In this commit, Rib class
exposes a `mockFibResponse` function variable, so that test cases
can directly specify FibUpdater's response without needing to invoke
private methods. This further allows replacing these private methods
with lambdas.
Also, logic for beginning RibUpdateBatch is abstracted out of control
command handlers, in preparation for PrefixAnnouncement-based RIB
update functions.
refs #4683
Change-Id: I0c95d8daa1458c704c7352a7809e6bed69134642
diff --git a/rib/rib.hpp b/rib/rib.hpp
index c8a0f5d..a2539b8 100644
--- a/rib/rib.hpp
+++ b/rib/rib.hpp
@@ -175,8 +175,16 @@
sendBatchFromQueue();
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- // Used by RibManager unit-tests to get sent batch to simulate successful FIB update
- std::function<void(RibUpdateBatch)> m_onSendBatchFromQueue;
+#ifdef WITH_TESTS
+ /** \brief In unit tests, mock FIB update result.
+ *
+ * If the callback is not nullptr, sendBatchFromQueue() immediately succeeds or fails according
+ * to the return value of callback function.
+ */
+ std::function<bool(const RibUpdateBatch&)> mockFibResponse;
+
+ bool wantMockFibResponseOnce = false; ///< if true, mockFibResponse is cleared after every use.
+#endif
void
erase(const Name& prefix, const Route& route);