From d77840bf518a04b0f8ad4676d34a758f2821763c Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Tue, 16 Jan 2018 20:49:00 +0000 Subject: [PATCH] Add second smooth recovery test. --- src/baseproc-service.cc | 2 +- src/tests/proctests.cc | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/baseproc-service.cc b/src/baseproc-service.cc index ce94f7b..3d0d01f 100644 --- a/src/baseproc-service.cc +++ b/src/baseproc-service.cc @@ -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) diff --git a/src/tests/proctests.cc b/src/tests/proctests.cc index 9e82739..25d4736 100644 --- a/src/tests/proctests.cc +++ b/src/tests/proctests.cc @@ -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> command_offsets; + command_offsets.emplace_back(0, command.length()); + std::list 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, ""); } -- 2.25.1