tests: Fix failure of NameServer and Validator test suites

The fix makes sure that DummyFace::receive does not called from within
signal invocation.

Change-Id: Idc6d2866ece585932687c0bafe7731a6fa66ddea
diff --git a/tests/unit/daemon/name-server.cpp b/tests/unit/daemon/name-server.cpp
index 0e5f302..f2b64bb 100644
--- a/tests/unit/daemon/name-server.cpp
+++ b/tests/unit/daemon/name-server.cpp
@@ -311,9 +311,14 @@
   {
     // ensure prefix is registered
     run();
-    validatorFace->onSendInterest.connect([&] (const Interest& interest) {
+
+    validatorFace->onSendInterest.connect([this] (const Interest& interest) {
       NDNS_LOG_TRACE("validatorFace get Interest: " << interest.getName());
-      face->receive(interest);
+
+      shared_ptr<const Interest> i = interest.shared_from_this();
+      io.post([i, this] {
+          face->receive(*i);
+        });
     });
   }
 
@@ -386,9 +391,12 @@
   bool hasDataBack = false;
 
   shared_ptr<Regex> regex = make_shared<Regex>("(<>*)<KEY>(<>+)<ID-CERT><>");
-  face->onSendData.connectSingleShot([&] (const Data& data) {
+  face->onSendData.connect([&] (const Data& data) {
     if (regex->match(data.getName())) {
-      validatorFace->receive(data); // It's data requested by validator
+      shared_ptr<const Data> d = data.shared_from_this();
+      io.post([d, this] {
+          validatorFace->receive(*d); // It's data requested by validator
+        });
     }
     else {
       // cert is requested by validator
diff --git a/tests/unit/validator.cpp b/tests/unit/validator.cpp
index e51782b..09af09d 100644
--- a/tests/unit/validator.cpp
+++ b/tests/unit/validator.cpp
@@ -132,7 +132,9 @@
     NDNS_LOG_TRACE("validator needs: " << certName);
     BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName), true);
     auto cert = m_keyChain.getCertificate(certName);
-    m_face->receive<Data>(*cert);
+    m_face->getIoService().post([this, cert] {
+        m_face->receive<Data>(*cert);
+      });
   }
 
 public: