Improve a test (and make it pass).
authorDavin McCall <davmac@davmac.org>
Thu, 7 Sep 2017 19:05:39 +0000 (20:05 +0100)
committerDavin McCall <davmac@davmac.org>
Thu, 7 Sep 2017 19:05:39 +0000 (20:05 +0100)
When a service is unpinned from pinned start, it needs to check
force_stop and stop if set.

src/service.cc
src/tests/tests.cc

index c170dad12758f100a1c228d466bccf4a5bb0b963..e2ba25158a1833f411551e87f2079f7ebff8761d 100644 (file)
@@ -1284,7 +1284,7 @@ void service_record::unpin() noexcept
 {
     if (pinned_started) {
         pinned_started = false;
-        if (desired_state == service_state_t::STOPPED) {
+        if (desired_state == service_state_t::STOPPED || force_stop) {
             do_stop();
             services->process_queues();
         }
index 71102926f02292627ee21c6d452c1c19e7f9089a..26f5613c14bd02983780fda646911793ee35f4bd 100644 (file)
@@ -210,6 +210,14 @@ void test6()
     assert(s3->get_state() == service_state_t::STARTED);
     assert(s2->get_state() == service_state_t::STOPPING);
     assert(s1->get_state() == service_state_t::STARTED);
+
+    // If we now unpin, s3 should stop:
+    s3->unpin();
+    sset.process_queues();
+    assert(s3->get_state() == service_state_t::STOPPED);
+    assert(s2->get_state() == service_state_t::STOPPED);
+    // s1 will stop because it is no longer required:
+    assert(s1->get_state() == service_state_t::STOPPED);
 }
 
 // Test 7: stopping a soft dependency doesn't cause the dependent to stop.