Dispatching in the main thread 70/44170/6
authorJan Olszak <j.olszak@samsung.com>
Tue, 14 Jul 2015 12:59:32 +0000 (14:59 +0200)
committerJan Olszak <j.olszak@samsung.com>
Wed, 22 Jul 2015 16:20:10 +0000 (18:20 +0200)
[Feature]       Removed Server's ThreadDispatcher
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, install, run tests

Change-Id: I100f8b370baeca78cbfcfdc803e360ebc40fd0ca

17 files changed:
libs/ipc/client.cpp
libs/ipc/client.hpp
libs/ipc/internals/finish-request.hpp
libs/ipc/internals/processor.cpp
libs/ipc/internals/processor.hpp
libs/ipc/service.cpp
libs/ipc/service.hpp
server/host-ipc-connection.cpp
server/host-ipc-connection.hpp
server/main.cpp
server/server.cpp
server/server.hpp
server/zones-manager.cpp
server/zones-manager.hpp
tests/unit_tests/client/ut-client.cpp
tests/unit_tests/server/ut-server.cpp
tests/unit_tests/server/ut-zones-manager.cpp

index eb7f8d2..ad2eb47 100644 (file)
@@ -69,13 +69,13 @@ bool Client::isStarted()
     return mProcessor.isStarted();
 }
 
-void Client::stop()
+void Client::stop(bool wait)
 {
     if (!mProcessor.isStarted()) {
         return;
     }
     LOGS("Client stop");
-    mProcessor.stop();
+    mProcessor.stop(wait);
 }
 
 void Client::handle(const FileDescriptor fd, const epoll::Events pollEvents)
index fe3345a..e083166 100644 (file)
@@ -65,8 +65,10 @@ public:
 
     /**
      * Stops processing
+     *
+     * @param wait does it block waiting for all internals to stop
      */
-    void stop();
+    void stop(bool wait = true);
 
     /**
      * Set the callback called for each new connection to a peer
index 934c135..5a948bd 100644 (file)
@@ -43,4 +43,4 @@ public:
 
 } // namespace ipc
 
-#endif // COMMON_IPC_INTERNALS_FINISH_REQUEST_HPP
+#endif // COMMON_IPC_INTERNALS_FINISH_REQUEST_HPP
\ No newline at end of file
index 3b6d790..8f81b24 100644 (file)
@@ -78,7 +78,7 @@ Processor::~Processor()
 {
     LOGS(mLogPrefix + "Processor Destructor");
     try {
-        stop();
+        stop(false);
     } catch (std::exception& e) {
         LOGE(mLogPrefix + "Error in Processor's destructor: " << e.what());
     }
@@ -117,7 +117,7 @@ void Processor::start()
     }
 }
 
-void Processor::stop()
+void Processor::stop(bool wait)
 {
     LOGS(mLogPrefix + "Processor stop");
 
@@ -129,14 +129,16 @@ void Processor::stop()
             mRequestQueue.pushBack(Event::FINISH, request);
         }
 
-        LOGD(mLogPrefix + "Waiting for the Processor to stop");
+        if(wait){
+            LOGD(mLogPrefix + "Waiting for the Processor to stop");
 
-        // Wait till the FINISH request is served
-        Lock lock(mStateMutex);
-        conditionPtr->wait(lock, [this]() {
-            return !mIsRunning;
-        });
-        assert(mPeerInfo.empty());
+            // Wait till the FINISH request is served
+            Lock lock(mStateMutex);
+            conditionPtr->wait(lock, [this]() {
+                return !mIsRunning;
+            });
+            assert(mPeerInfo.empty());
+        }
     }
 }
 
@@ -200,7 +202,7 @@ PeerID Processor::addPeer(const std::shared_ptr<Socket>& socketPtr)
     mRequestQueue.pushBack(Event::ADD_PEER, requestPtr);
 
     LOGI(mLogPrefix + "Add Peer Request. Id: " << requestPtr->peerID
-            << ", fd: " << socketPtr->getFD());
+         << ", fd: " << socketPtr->getFD());
 
     return requestPtr->peerID;
 }
@@ -690,8 +692,8 @@ bool Processor::onFinishRequest(FinishRequest& requestFinisher)
 
     mEventPoll.removeFD(mRequestQueue.getFD());
     mIsRunning = false;
-    requestFinisher.conditionPtr->notify_all();
 
+    requestFinisher.conditionPtr->notify_all();
     return true;
 }
 
index b3ca9fb..4d0089f 100644 (file)
@@ -145,8 +145,10 @@ public:
     /**
      * Stops the processing thread.
      * No incoming data will be handled after.
+     *
+     * @param wait does it block waiting for all internals to stop
      */
-    void stop();
+    void stop(bool wait);
 
     /**
      * Set the callback called for each new connection to a peer
@@ -470,7 +472,7 @@ private:
     bool onAddPeerRequest(AddPeerRequest& request);
     bool onRemovePeerRequest(RemovePeerRequest& request);
     bool onSendResultRequest(SendResultRequest& request);
-    bool onFinishRequest(FinishRequest& requestFinisher);
+    bool onFinishRequest(FinishRequest& request);
 
     bool onReturnValue(Peers::iterator& peerIt,
                        const MessageID messageID);
index 2e3dbe7..04cd542 100644 (file)
@@ -72,13 +72,13 @@ bool Service::isStarted()
     return mProcessor.isStarted();
 }
 
-void Service::stop()
+void Service::stop(bool wait)
 {
     if (!mProcessor.isStarted()) {
         return;
     }
     LOGS("Service stop");
-    mProcessor.stop();
+    mProcessor.stop(wait);
 }
 
 void Service::handle(const FileDescriptor fd, const epoll::Events pollEvents)
index 5b6297c..5e73a71 100644 (file)
@@ -70,8 +70,10 @@ public:
 
     /**
      * Stops all working threads
+     *
+     * @param wait does it block waiting for all internals to stop
      */
-    void stop();
+    void stop(bool wait = true);
 
     /**
     * Set the callback called for each new connection to a peer
index 79cd7af..d3684b9 100644 (file)
@@ -148,6 +148,17 @@ void HostIPCConnection::start()
     LOGD("Connected");
 }
 
+void HostIPCConnection::stop(bool wait)
+{
+    LOGT("Stopping IPC");
+    mService->stop(wait);
+}
+
+bool HostIPCConnection::isRunning()
+{
+    return mService->isStarted();
+}
+
 void HostIPCConnection::setLockQueueCallback(const Method<api::Void>::type& callback)
 {
     typedef IPCMethodWrapper<api::Void> Callback;
index 15620bf..da3dbd4 100644 (file)
@@ -52,7 +52,9 @@ public:
     ~HostIPCConnection();
 
     void start();
+    void stop(bool wait);
     void signalZoneConnectionState(const api::ConnectionState& connectionState);
+    bool isRunning();
 
 private:
     void setLockQueueCallback(const Method<api::Void>::type& callback);
index 83556b5..fafa788 100644 (file)
@@ -129,9 +129,11 @@ int main(int argc, char* argv[])
         // TODO: SIGTERM used by lxc, get rid of this
         utils::signalIgnore({SIGTERM});
 
+        LOGI("Starting daemon...");
         Server server(CONFIG_PATH);
         server.run(runAsRoot);
         server.reloadIfRequired(argv);
+        LOGI("Daemon stopped");
 
     } catch (std::exception& e) {
         LOGE("Unexpected: " << utils::getTypeName(e) << ": " << e.what());
index f48d291..a42d239 100644 (file)
 #include "config.hpp"
 
 #include "server.hpp"
-#include "zones-manager.hpp"
 #include "exception.hpp"
 
 #include "config/manager.hpp"
 #include "logger/logger.hpp"
-#include "utils/glib-loop.hpp"
 #include "utils/environment.hpp"
 #include "utils/fs.hpp"
 #include "utils/signal.hpp"
@@ -40,6 +38,7 @@
 #include <csignal>
 #include <cerrno>
 #include <string>
+#include <functional>
 #include <cstring>
 #include <unistd.h>
 #include <pwd.h>
@@ -78,23 +77,32 @@ using namespace utils;
 namespace vasum {
 
 Server::Server(const std::string& configPath)
-    : mIsUpdate(false),
+    : mIsRunning(true),
+      mIsUpdate(false),
       mConfigPath(configPath),
-      mSignalFD(mDispatcher.getPoll())
+      mSignalFD(mEventPoll),
+      mZonesManager(mEventPoll, mConfigPath),
+      mDispatchingThread(::pthread_self())
 {
-    mSignalFD.setHandlerAndBlock(SIGUSR1, [this] (int) {
-        LOGD("Received SIGUSR1 - triggering update.");
-        mIsUpdate = true;
-        mStopLatch.set();
-    });
-
-    mSignalFD.setHandlerAndBlock(SIGINT, [this](int) {
-        mStopLatch.set();
-    });
-
-    mSignalFD.setHandler(SIGTERM, [this] (int) {
-        mStopLatch.set();
-    });
+    mSignalFD.setHandlerAndBlock(SIGUSR1, std::bind(&Server::handleUpdate, this));
+    mSignalFD.setHandlerAndBlock(SIGINT, std::bind(&Server::handleStop, this));
+    mSignalFD.setHandler(SIGTERM, std::bind(&Server::handleStop, this));
+}
+
+void Server::handleUpdate()
+{
+    LOGD("Received SIGUSR1 - triggering update.");
+    mZonesManager.setZonesDetachOnExit();
+    mZonesManager.stop(false);
+    mIsUpdate = true;
+    mIsRunning = false;
+}
+
+void Server::handleStop()
+{
+    LOGD("Stopping Server");
+    mZonesManager.stop(false);
+    mIsRunning = false;
 }
 
 void Server::run(bool asRoot)
@@ -103,30 +111,17 @@ void Server::run(bool asRoot)
         throw ServerException("Environment setup failed");
     }
 
-    LOGI("Starting daemon...");
-    {
-        utils::ScopedGlibLoop loop;
-        ZonesManager manager(mDispatcher.getPoll(), mConfigPath);
+    mZonesManager.start();
 
-        // Do not restore zones state at Vasum start
-        LOGI("Daemon started");
-
-        mStopLatch.wait();
-
-        // Detach zones if we triggered an update
-        if (mIsUpdate) {
-            manager.setZonesDetachOnExit();
-        }
-
-        LOGI("Stopping daemon...");
+    while(mIsRunning || mZonesManager.isRunning()) {
+        mEventPoll.dispatchIteration(-1);
     }
-    LOGI("Daemon stopped");
 }
 
 void Server::reloadIfRequired(char* argv[])
 {
     if (mIsUpdate) {
-        execve(argv[0], argv, environ);
+        ::execve(argv[0], argv, environ);
         LOGE("Failed to reload " << argv[0] << ": " << getSystemErrorMessage());
     }
 }
@@ -134,7 +129,12 @@ void Server::reloadIfRequired(char* argv[])
 void Server::terminate()
 {
     LOGI("Terminating server");
-    mStopLatch.set();
+    int ret = ::pthread_kill(mDispatchingThread, SIGINT);
+    if(ret != 0) {
+        const std::string msg = utils::getSystemErrorMessage(ret);
+        LOGE("Error during Server termination: " << msg);
+        throw ServerException("Error during Server termination: " + msg);
+    }
 }
 
 bool Server::checkEnvironment()
index 0d10396..a688653 100644 (file)
 #ifndef SERVER_SERVER_HPP
 #define SERVER_SERVER_HPP
 
+#include "zones-manager.hpp"
+
 #include "utils/latch.hpp"
 #include "utils/signalfd.hpp"
-#include "ipc/epoll/thread-dispatcher.hpp"
+#include "utils/glib-loop.hpp"
+#include "ipc/epoll/event-poll.hpp"
 
 #include <atomic>
 #include <string>
+#include <pthread.h>
 
 
 namespace vasum {
@@ -63,16 +67,23 @@ public:
     static bool checkEnvironment();
 
 private:
-    std::atomic_bool mIsUpdate;
+    bool mIsRunning;
+    bool mIsUpdate;
     std::string mConfigPath;
-    utils::Latch mStopLatch;
-    ipc::epoll::ThreadDispatcher mDispatcher;
+    utils::ScopedGlibLoop loop;
+    ipc::epoll::EventPoll mEventPoll;
     utils::SignalFD mSignalFD;
+    ZonesManager mZonesManager;
+    ::pthread_t mDispatchingThread;
+
     /**
      * Set needed caps, groups and drop root privileges.
      */
     static bool prepareEnvironment(const std::string& configPath, bool runAsRoot);
 
+    void handleUpdate();
+    void handleStop();
+
 };
 
 
index 8ed51e1..0787be0 100644 (file)
@@ -101,10 +101,11 @@ bool zoneIsRunning(const std::unique_ptr<Zone>& zone) {
 
 
 ZonesManager::ZonesManager(ipc::epoll::EventPoll& eventPoll, const std::string& configPath)
-    : mWorker(utils::Worker::create())
-    , mHostIPCConnection(eventPoll, this)
+    : mIsRunning(true)
+    , mWorker(utils::Worker::create())
     , mDetachOnExit(false)
     , mExclusiveIDLock(INVALID_CONNECTION_ID)
+    , mHostIPCConnection(eventPoll, this)
 #ifdef DBUS_CONNECTION
     , mHostDbusConnection(this)
 #endif
@@ -116,12 +117,27 @@ ZonesManager::ZonesManager(ipc::epoll::EventPoll& eventPoll, const std::string&
                                         configPath,
                                         mDynamicConfig,
                                         getVasumDbPrefix());
+}
+
+ZonesManager::~ZonesManager()
+{
+    LOGD("Destroying ZonesManager object...");
+    stop(true);
+}
+
+void ZonesManager::start()
+{
+    Lock lock(mMutex);
+
+    LOGD("Starting ZonesManager");
+
+    mIsRunning = true;
 
 #ifdef DBUS_CONNECTION
     using namespace std::placeholders;
     mProxyCallPolicy.reset(new ProxyCallPolicy(mConfig.proxyCallRules));
-    mHostDbusConnection.setProxyCallCallback(bind(&ZonesManager::handleProxyCall,
-                                                  this, HOST_ID, _1, _2, _3, _4, _5, _6, _7));
+    mHostDbusConnection.setProxyCallCallback(std::bind(&ZonesManager::handleProxyCall,
+                                                       this, HOST_ID, _1, _2, _3, _4, _5, _6, _7));
 #endif //DBUS_CONNECTION
 
     for (const auto& zoneId : mDynamicConfig.zoneIds) {
@@ -144,9 +160,14 @@ ZonesManager::ZonesManager(ipc::epoll::EventPoll& eventPoll, const std::string&
     mHostIPCConnection.start();
 }
 
-ZonesManager::~ZonesManager()
+void ZonesManager::stop(bool wait)
 {
-    LOGD("Destroying ZonesManager object...");
+    Lock lock(mMutex);
+    LOGD("Stopping ZonesManager");
+
+    if(!mIsRunning) {
+        return;
+    }
 
     if (!mDetachOnExit) {
         try {
@@ -155,10 +176,17 @@ ZonesManager::~ZonesManager()
             LOGE("Failed to shutdown all of the zones");
         }
     }
+
     // wait for all tasks to complete
     mWorker.reset();
+    mHostIPCConnection.stop(wait);
+    mIsRunning = false;
+}
 
-    LOGD("ZonesManager object destroyed");
+bool ZonesManager::isRunning()
+{
+    Lock lock(mMutex);
+    return mIsRunning ||  mHostIPCConnection.isRunning();
 }
 
 ZonesManager::Zones::iterator ZonesManager::findZone(const std::string& id)
index 4d18bf7..6a7a2c4 100644 (file)
@@ -55,6 +55,24 @@ public:
     ~ZonesManager();
 
     /**
+     * Request stopping the manager.
+     *
+     * @param wait does it block waiting for all internals to stop
+     */
+    void stop(bool wait);
+
+    /**
+     * Starts the manager
+     */
+    void start();
+
+    /**
+     * If ZoneManager is running it needs the external polling loop to operate.
+     * @return is manager still running
+     */
+    bool isRunning();
+
+    /**
      * Create new zone.
      *
      * @param zoneId id of new zone
@@ -183,11 +201,11 @@ private:
     typedef std::recursive_mutex Mutex;
     typedef std::unique_lock<Mutex> Lock;
 
+    bool mIsRunning;
     utils::Worker::Pointer mWorker;
     Mutex mMutex; // used to protect mZones
     ZonesManagerConfig mConfig; //TODO make it const
     ZonesManagerDynamicConfig mDynamicConfig;
-    HostIPCConnection mHostIPCConnection;
     // to hold InputMonitor pointer to monitor if zone switching sequence is recognized
     std::unique_ptr<InputMonitor> mSwitchingSequenceMonitor;
     // like set but keep insertion order
@@ -216,6 +234,7 @@ private:
     void insertZone(const std::string& zoneId, const std::string& templatePath);
     void tryAddTask(const utils::Worker::Task& task, api::MethodResultBuilder::Pointer result, bool wait);
 
+    HostIPCConnection mHostIPCConnection;
 #ifdef DBUS_CONNECTION
     HostDbusConnection mHostDbusConnection;
     std::unique_ptr<ProxyCallPolicy> mProxyCallPolicy;
index b352b9c..1681c36 100644 (file)
@@ -74,6 +74,7 @@ struct Fixture {
         , mRunGuard("/tmp/ut-run")
         , cm(new ZonesManager(mDispatcher.getPoll(), TEST_CONFIG_PATH))
     {
+        cm->start();
         cm->createZone("zone1", TEMPLATE_NAME);
         cm->createZone("zone2", TEMPLATE_NAME);
         cm->createZone("zone3", TEMPLATE_NAME);
index 6f21872..e4d1ce4 100644 (file)
@@ -33,6 +33,7 @@
 #include "utils/glib-loop.hpp"
 #include "utils/scoped-dir.hpp"
 #include "logger/logger.hpp"
+#include "ipc/epoll/thread-dispatcher.hpp"
 
 #include <string>
 #include <future>
@@ -54,7 +55,6 @@ const bool AS_ROOT = true;
 
 struct Fixture {
     utils::ScopedDir mZonesPathGuard;
-    ipc::epoll::ThreadDispatcher mDispatcher;
 
     Fixture()
         : mZonesPathGuard(ZONES_PATH)
@@ -66,10 +66,13 @@ struct Fixture {
     void prepare()
     {
         ScopedGlibLoop loop;
+        ipc::epoll::ThreadDispatcher mDispatcher;
         ZonesManager manager(mDispatcher.getPoll(), TEST_CONFIG_PATH);
+        manager.start();
         manager.createZone("zone1", TEMPLATE_NAME);
         manager.createZone("zone2", TEMPLATE_NAME);
         manager.restoreAll();
+        manager.stop(true);
     }
 };
 } // namespace
@@ -106,12 +109,13 @@ BOOST_AUTO_TEST_CASE(TerminateRun)
 BOOST_AUTO_TEST_CASE(RunTerminate)
 {
     Server s(TEST_CONFIG_PATH);
-    std::future<void> runFuture = std::async(std::launch::async, [&] {s.run(AS_ROOT);});
+    std::future<void> runFuture = std::async(std::launch::async, [&] {
+        // give a chance to run
+        std::this_thread::sleep_for(std::chrono::milliseconds(200));
+        s.terminate();
+    });
 
-    // give a chance to run a thread
-    std::this_thread::sleep_for(std::chrono::milliseconds(200));
-
-    s.terminate();
+    s.run(AS_ROOT);
     runFuture.wait();
 
     // a potential exception from std::async thread will be delegated to this thread
index a6502fd..214ed1a 100644 (file)
@@ -624,6 +624,7 @@ BOOST_AUTO_TEST_CASE(MissingConfig)
 BOOST_AUTO_TEST_CASE(Create)
 {
     ZonesManager cm(dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
 }
@@ -631,6 +632,7 @@ BOOST_AUTO_TEST_CASE(Create)
 BOOST_AUTO_TEST_CASE(StartStop)
 {
     ZonesManager cm(dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
 
@@ -644,6 +646,7 @@ BOOST_AUTO_TEST_CASE(DetachOnExit)
 {
     {
         ZonesManager cm(dispatcher.getPoll(), TEST_CONFIG_PATH);
+        cm.start();
         cm.createZone("zone1", SIMPLE_TEMPLATE);
         cm.createZone("zone2", SIMPLE_TEMPLATE);
         cm.restoreAll();
@@ -652,6 +655,7 @@ BOOST_AUTO_TEST_CASE(DetachOnExit)
     }
     {
         ZonesManager cm(dispatcher.getPoll(), TEST_CONFIG_PATH);
+        cm.start();
         cm.restoreAll();
         BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), "zone1");
     }
@@ -660,6 +664,7 @@ BOOST_AUTO_TEST_CASE(DetachOnExit)
 BOOST_AUTO_TEST_CASE(Focus)
 {
     ZonesManager cm(dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
     cm.createZone("zone3", SIMPLE_TEMPLATE);
@@ -677,6 +682,7 @@ BOOST_AUTO_TEST_CASE(Focus)
 MULTI_FIXTURE_TEST_CASE(SwitchToDefault, F, ACCESSORS)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
     cm.createZone("zone3", SIMPLE_TEMPLATE);
@@ -700,6 +706,7 @@ MULTI_FIXTURE_TEST_CASE(SwitchToDefault, F, ACCESSORS)
 MULTI_FIXTURE_TEST_CASE(AllowSwitchToDefault, F, ACCESSORS)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
     cm.createZone("zone3", SIMPLE_TEMPLATE);
@@ -734,6 +741,7 @@ MULTI_FIXTURE_TEST_CASE(AllowSwitchToDefault, F, ACCESSORS)
 MULTI_FIXTURE_TEST_CASE(ProxyCall, F, DbusFixture)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
     cm.createZone("zone3", SIMPLE_TEMPLATE);
@@ -787,6 +795,7 @@ const std::set<std::string> EXPECTED_CONNECTIONS_NONE = { "zone1", "zone2", "zon
 MULTI_FIXTURE_TEST_CASE(GetZoneIds, F, ACCESSORS)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
     cm.createZone("zone3", SIMPLE_TEMPLATE);
@@ -804,6 +813,7 @@ MULTI_FIXTURE_TEST_CASE(GetZoneIds, F, ACCESSORS)
 MULTI_FIXTURE_TEST_CASE(GetActiveZoneId, F, ACCESSORS)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
     cm.createZone("zone3", SIMPLE_TEMPLATE);
@@ -827,6 +837,7 @@ MULTI_FIXTURE_TEST_CASE(GetActiveZoneId, F, ACCESSORS)
 MULTI_FIXTURE_TEST_CASE(SetActiveZone, F, ACCESSORS)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
     cm.createZone("zone3", SIMPLE_TEMPLATE);
@@ -860,6 +871,7 @@ MULTI_FIXTURE_TEST_CASE(CreateDestroyZone, F, ACCESSORS)
     const std::string zone3 = "test3";
 
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.restoreAll();
 
     BOOST_CHECK_EQUAL(cm.getRunningForegroundZoneId(), "");
@@ -916,6 +928,7 @@ MULTI_FIXTURE_TEST_CASE(CreateDestroyZonePersistence, F, ACCESSORS)
 
     auto getZoneIds = [this]() -> std::vector<std::string> {
         ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+        cm.start();
         cm.restoreAll();
 
         typename F::HostAccessory host;
@@ -927,6 +940,7 @@ MULTI_FIXTURE_TEST_CASE(CreateDestroyZonePersistence, F, ACCESSORS)
     // create zone
     {
         ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+        cm.start();
         typename F::HostAccessory host;
         host.callAsyncMethodCreateZone(zone, SIMPLE_TEMPLATE, resultCallback);
         BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT));
@@ -941,6 +955,7 @@ MULTI_FIXTURE_TEST_CASE(CreateDestroyZonePersistence, F, ACCESSORS)
     // destroy zone
     {
         ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+        cm.start();
         typename F::HostAccessory host;
         host.callAsyncMethodDestroyZone(zone, resultCallback);
         BOOST_REQUIRE(callDone.wait(EVENT_TIMEOUT));
@@ -965,6 +980,7 @@ MULTI_FIXTURE_TEST_CASE(ZoneStatePersistence, F, ACCESSORS)
     // firts run
     {
         ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+        cm.start();
         typename F::HostAccessory host;
 
         // zone1 - created
@@ -1010,6 +1026,7 @@ MULTI_FIXTURE_TEST_CASE(ZoneStatePersistence, F, ACCESSORS)
     // second run
     {
         ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+        cm.start();
         cm.restoreAll();
 
         BOOST_CHECK(cm.isRunning(zone1)); // because the default json value
@@ -1026,6 +1043,7 @@ MULTI_FIXTURE_TEST_CASE(StartShutdownZone, F, ACCESSORS)
     const std::string zone2 = "zone2";
 
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone(zone1, SIMPLE_TEMPLATE);
     cm.createZone(zone2, SIMPLE_TEMPLATE);
 
@@ -1063,6 +1081,7 @@ MULTI_FIXTURE_TEST_CASE(StartShutdownZone, F, ACCESSORS)
 MULTI_FIXTURE_TEST_CASE(LockUnlockZone, F, ACCESSORS)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.createZone("zone2", SIMPLE_TEMPLATE);
     cm.createZone("zone3", SIMPLE_TEMPLATE);
@@ -1109,6 +1128,7 @@ MULTI_FIXTURE_TEST_CASE(LockUnlockZone, F, ACCESSORS)
 MULTI_FIXTURE_TEST_CASE(CreateFile, F, ACCESSORS)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.restoreAll();
 
@@ -1129,6 +1149,7 @@ MULTI_FIXTURE_TEST_CASE(CreateFile, F, ACCESSORS)
 MULTI_FIXTURE_TEST_CASE(CreateWriteReadFile, F, ACCESSORS)
 {
     ZonesManager cm(F::dispatcher.getPoll(), TEST_CONFIG_PATH);
+    cm.start();
     cm.createZone("zone1", SIMPLE_TEMPLATE);
     cm.restoreAll();