Tests: add a new test.
authorDavin McCall <davmac@davmac.org>
Mon, 18 Jun 2018 20:28:54 +0000 (21:28 +0100)
committerDavin McCall <davmac@davmac.org>
Mon, 18 Jun 2018 20:29:12 +0000 (21:29 +0100)
src/tests/proctests.cc

index fa437170b4108fd26ad73125244e9b1e200d7cae..b6c2294aa331c8e0b499c68180fcd7bf225a74f9 100644 (file)
@@ -163,6 +163,57 @@ void test_term_via_stop()
     sset.remove_service(&p);
 }
 
+// Termination via stop request, ensure reason is reset:
+void test_term_via_stop2()
+{
+    using namespace std;
+
+    service_set sset;
+
+    string command = "test-command";
+    list<pair<unsigned,unsigned>> command_offsets;
+    command_offsets.emplace_back(0, command.length());
+    std::list<prelim_dep> depends;
+
+    process_service p = process_service(&sset, "testproc", std::move(command), command_offsets, depends);
+    init_service_defaults(p);
+    sset.add_service(&p);
+
+    p.start(true);
+    sset.process_queues();
+
+    // first set it up with failure reason:
+
+    base_process_service_test::exec_failed(&p, ENOENT);
+    sset.process_queues();
+
+    assert(p.get_state() == service_state_t::STOPPED);
+    assert(p.get_stop_reason() == stopped_reason_t::EXECFAILED);
+
+    // now restart clean:
+
+    p.start(true);
+    sset.process_queues();
+
+    base_process_service_test::exec_succeeded(&p);
+    sset.process_queues();
+
+    assert(p.get_state() == service_state_t::STARTED);
+    assert(event_loop.active_timers.size() == 0);
+
+    p.stop(true);
+    sset.process_queues();
+    assert(p.get_state() == service_state_t::STOPPING);
+
+    base_process_service_test::handle_exit(&p, 0);
+    sset.process_queues();
+    assert(p.get_state() == service_state_t::STOPPED);
+    assert(p.get_stop_reason() == stopped_reason_t::NORMAL);
+    assert(event_loop.active_timers.size() == 0);
+
+    sset.remove_service(&p);
+}
+
 // Time-out during start
 void test_proc_start_timeout()
 {
@@ -681,6 +732,7 @@ int main(int argc, char **argv)
     RUN_TEST(test_proc_service_start, "   ");
     RUN_TEST(test_proc_unexpected_term, " ");
     RUN_TEST(test_term_via_stop, "        ");
+    RUN_TEST(test_term_via_stop2, "       ");
     RUN_TEST(test_proc_start_timeout, "   ");
     RUN_TEST(test_proc_start_timeout2, "  ");
     RUN_TEST(test_proc_start_execfail, "  ");