Fix the stopping of the container in the ContainerSuite tests 33/22433/2
authorLukasz Pawelczyk <l.pawelczyk@partner.samsung.com>
Tue, 3 Jun 2014 11:42:00 +0000 (13:42 +0200)
committerJan Olszak <j.olszak@samsung.com>
Thu, 5 Jun 2014 10:32:32 +0000 (03:32 -0700)
[Bug/Feature]   The test took 10 seconds cause we issued a stop command
                before the container had a chance to start, effectively ignoring
                the stop command. The 10 seconds timeout triggered after which
                the container had been destroyed.
[Cause]         There is no proper way to know that the system inside the
                container has booted.
[Solution]      Add some small timeout to allow the container to start properly.
                Same thing is done in ContainerAdminSuite. There doesn't seem to
                be a better way for that.
[Verification]  Built, installed and run the tests.

Change-Id: I837588f93b335adab4ac5561b3a686af602e0c15
Signed-off-by: Lukasz Pawelczyk <l.pawelczyk@partner.samsung.com>
tests/unit_tests/server/ut-container-admin.cpp
tests/unit_tests/server/ut-container.cpp

index 7d534d9..9cca1c2 100644 (file)
@@ -55,7 +55,6 @@ const unsigned int WAIT_STOP_TIMEOUT = 15 * 1000;
 
 void ensureStarted()
 {
-    // TODO: fix the libvirt usage so this is not required
     std::this_thread::sleep_for(std::chrono::milliseconds(200));
 }
 
index da6479e..bd60e23 100644 (file)
@@ -34,6 +34,8 @@
 
 #include <memory>
 #include <string>
+#include <thread>
+#include <chrono>
 
 
 using namespace security_containers;
@@ -46,6 +48,11 @@ const std::string TEST_DBUS_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut
 const std::string BUGGY_CONFIG_PATH = SC_TEST_CONFIG_INSTALL_DIR "/server/ut-container/containers/buggy.conf";
 const std::string MISSING_CONFIG_PATH = "/this/is/a/missing/file/path/config.conf";
 
+void ensureStarted()
+{
+    std::this_thread::sleep_for(std::chrono::milliseconds(200));
+}
+
 struct Fixture {
     utils::ScopedGlibLoop mLoop;
 };
@@ -80,6 +87,7 @@ BOOST_AUTO_TEST_CASE(StartStopTest)
 {
     std::unique_ptr<Container> c(new Container(TEST_CONFIG_PATH));
     BOOST_REQUIRE_NO_THROW(c->start());
+    ensureStarted();
     BOOST_REQUIRE_NO_THROW(c->stop());
 }
 
@@ -88,6 +96,7 @@ BOOST_AUTO_TEST_CASE(DbusConnectionTest)
     std::unique_ptr<Container> c;
     BOOST_REQUIRE_NO_THROW(c.reset(new Container(TEST_DBUS_CONFIG_PATH)));
     BOOST_REQUIRE_NO_THROW(c->start());
+    ensureStarted();
     BOOST_REQUIRE_NO_THROW(c->stop());
 }