Add second smooth recovery test.
authorDavin McCall <davmac@davmac.org>
Tue, 16 Jan 2018 20:49:00 +0000 (20:49 +0000)
committerDavin McCall <davmac@davmac.org>
Tue, 16 Jan 2018 20:49:00 +0000 (20:49 +0000)
src/baseproc-service.cc
src/tests/proctests.cc

index ce94f7bf1688cd3564c3d0e4841c71dbbbd2de44..3d0d01fb4b72fbc66a189e5010b82d85861b511d 100644 (file)
@@ -260,7 +260,7 @@ bool base_process_service::restart_ps_process() noexcept
         }
     }
 
-    // Check if enough time has lapsed since the prevous restart. If not, start a timer:
+    // Check if enough time has lapsed since the previous restart. If not, start a timer:
     time_val tdiff = current_time - last_start_time;
     if (restart_delay <= tdiff) {
         // > restart delay (normally 200ms)
index 9e8273909c1cf734f40f9ed611a0bb7ba231c5c4..25d473692dc3c6148c052555c874f7eb19d8003f 100644 (file)
@@ -190,7 +190,7 @@ void test_proc_stop_timeout()
 }
 
 // Smooth recovery
-void test_proc_smooth_recovery()
+void test_proc_smooth_recovery1()
 {
     using namespace std;
 
@@ -229,6 +229,38 @@ void test_proc_smooth_recovery()
     assert(p.get_state() == service_state_t::STARTED);
 }
 
+void test_proc_smooth_recovery2()
+{
+    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);
+    p.set_smooth_recovery(true);
+    p.set_restart_delay(time_val(0, 0));
+
+    p.start(true);
+    sset.process_queues();
+
+    base_process_service_test::exec_succeeded(&p);
+    sset.process_queues();
+
+    pid_t first_instance = bp_sys::last_forked_pid;
+
+    assert(p.get_state() == service_state_t::STARTED);
+
+    base_process_service_test::handle_exit(&p, 0);
+    sset.process_queues();
+
+    // no restart delay, process should restart immediately:
+    assert(first_instance + 1 == bp_sys::last_forked_pid);
+    assert(p.get_state() == service_state_t::STARTED);
+}
 
 #define RUN_TEST(name, spacing) \
     std::cout << #name "..." spacing; \
@@ -242,5 +274,6 @@ int main(int argc, char **argv)
     RUN_TEST(test_term_via_stop, "        ");
     RUN_TEST(test_proc_start_timeout, "   ");
     RUN_TEST(test_proc_stop_timeout, "    ");
-    RUN_TEST(test_proc_smooth_recovery, " ");
+    RUN_TEST(test_proc_smooth_recovery1, "");
+    RUN_TEST(test_proc_smooth_recovery2, "");
 }