Fix test 6, add a new test (test 7).
authorDavin McCall <davmac@davmac.org>
Tue, 5 Sep 2017 21:51:29 +0000 (22:51 +0100)
committerDavin McCall <davmac@davmac.org>
Tue, 5 Sep 2017 21:51:29 +0000 (22:51 +0100)
src/tests/tests.cc

index cb297a93a30960489432a15cb9af7dba72d8391e..71102926f02292627ee21c6d452c1c19e7f9089a 100644 (file)
@@ -206,12 +206,40 @@ void test6()
     s2->stop(true);
     sset.process_queues();
 
-    // s2 should re-start due to s3:
+    // s3 should remain started:
     assert(s3->get_state() == service_state_t::STARTED);
-    assert(s2->get_state() == service_state_t::STARTED);
+    assert(s2->get_state() == service_state_t::STOPPING);
     assert(s1->get_state() == service_state_t::STARTED);
 }
 
+// Test 7: stopping a soft dependency doesn't cause the dependent to stop.
+void test7()
+{
+    service_set sset;
+
+    service_record *s1 = new service_record(&sset, "test-service-1", service_type::INTERNAL, {}, {});
+    service_record *s2 = new service_record(&sset, "test-service-2", service_type::INTERNAL, {s1}, {});
+    service_record *s3 = new service_record(&sset, "test-service-3", service_type::INTERNAL, {}, {s2});
+    sset.add_service(s1);
+    sset.add_service(s2);
+    sset.add_service(s3);
+
+    assert(sset.find_service("test-service-1") == s1);
+    assert(sset.find_service("test-service-2") == s2);
+    assert(sset.find_service("test-service-3") == s3);
+
+    // Start all three services:
+    sset.start_service(s3);
+
+    // Now stop s1, which should also force s2 but not s3 to stop:
+    sset.stop_service(s1);
+
+    assert(s3->get_state() == service_state_t::STARTED);
+    assert(s2->get_state() == service_state_t::STOPPED);
+    assert(s1->get_state() == service_state_t::STOPPED);
+}
+
+
 int main(int argc, char **argv)
 {
     std::cout << "test1... ";
@@ -235,6 +263,10 @@ int main(int argc, char **argv)
     std::cout << "PASSED" << std::endl;
 
     std::cout << "test6... ";
-    test5();
+    test6();
+    std::cout << "PASSED" << std::endl;
+
+    std::cout << "test7... ";
+    test7();
     std::cout << "PASSED" << std::endl;
 }