From: Davin McCall Date: Tue, 16 Jan 2018 17:59:36 +0000 (+0000) Subject: Fix smooth recovery test. X-Git-Tag: v0.08~28 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=52bd7fd50ae068e0bb0bda898f095d2a53059a0a;p=oweals%2Fdinit.git Fix smooth recovery test. The initial process death should cause the process to be restarted after the restart delay. The test didn't take the start delay into account. --- diff --git a/src/tests/Makefile b/src/tests/Makefile index 9f94055..05d2a2d 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -16,11 +16,11 @@ prepare-incdir: cd includes; ln -sf ../../includes/*.h . cd includes; ln -sf ../test-includes/*.h . -tests: prepare-incdir $(parent_objs) tests.o test-dinit.o test-bpsys.o - $(CXX) $(SANITIZEOPTS) -o tests $(parent_objs) tests.o test-dinit.o test-bpsys.o $(EXTRA_LIBS) +tests: prepare-incdir $(parent_objs) tests.o test-dinit.o test-bpsys.o test-run-child-proc.o + $(CXX) $(SANITIZEOPTS) -o tests $(parent_objs) tests.o test-dinit.o test-bpsys.o test-run-child-proc.o $(EXTRA_LIBS) -proctests: prepare-incdir $(parent_objs) proctests.o test-dinit.o test-bpsys.o - $(CXX) $(SANITIZEOPTS) -o proctests $(parent_objs) proctests.o test-dinit.o test-bpsys.o $(EXTRA_LIBS) +proctests: prepare-incdir $(parent_objs) proctests.o test-dinit.o test-bpsys.o test-run-child-proc.o + $(CXX) $(SANITIZEOPTS) -o proctests $(parent_objs) proctests.o test-dinit.o test-bpsys.o test-run-child-proc.o $(EXTRA_LIBS) $(objects): %.o: %.cc $(CXX) $(CXXOPTS) $(SANITIZEOPTS) -MMD -MP -Iincludes -I../dasynq -c $< -o $@ diff --git a/src/tests/proctests.cc b/src/tests/proctests.cc index f193dbe..9e82739 100644 --- a/src/tests/proctests.cc +++ b/src/tests/proctests.cc @@ -24,6 +24,7 @@ class base_process_service_test static void handle_exit(base_process_service *bsp, int exit_status) { + bsp->pid = -1; bsp->handle_exit_status(exit_status); } }; @@ -31,6 +32,7 @@ class base_process_service_test namespace bp_sys { // last signal sent: extern int last_sig_sent; + extern pid_t last_forked_pid; } // Regular service start @@ -208,11 +210,22 @@ void test_proc_smooth_recovery() 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(); + // since time hasn't been changed, we expect that the process has not yet been re-launched: + assert(first_instance == bp_sys::last_forked_pid); + assert(p.get_state() == service_state_t::STARTED); + + p.timer_expired(); + sset.process_queues(); + + // Now a new process should've been launched: + assert(first_instance + 1 == bp_sys::last_forked_pid); assert(p.get_state() == service_state_t::STARTED); } diff --git a/src/tests/test-bpsys.cc b/src/tests/test-bpsys.cc index a117d3a..e02d717 100644 --- a/src/tests/test-bpsys.cc +++ b/src/tests/test-bpsys.cc @@ -23,6 +23,7 @@ static int allocfd() namespace bp_sys { int last_sig_sent = -1; // last signal number sent, accessible for tests. +pid_t last_forked_pid = 1; // last forked process id (incremented each 'fork') int pipe2(int fds[2], int flags) { diff --git a/src/tests/test-includes/dinit.h b/src/tests/test-includes/dinit.h index 521f68f..ef945ca 100644 --- a/src/tests/test-includes/dinit.h +++ b/src/tests/test-includes/dinit.h @@ -9,6 +9,10 @@ using clock_type = dasynq::clock_type; using rearm = dasynq::rearm; using time_val = dasynq::time_val; +namespace bp_sys { + extern pid_t last_forked_pid; +} + class eventloop_t { public: @@ -22,7 +26,8 @@ class eventloop_t public: pid_t fork(eventloop_t &loop, bool reserved_child_watcher, int priority = dasynq::DEFAULT_PRIORITY) { - return 2; // doesn't matter much what we return here, but it should be a potentially valid pid + bp_sys::last_forked_pid++; + return bp_sys::last_forked_pid; } void add_reserved(eventloop_t &eloop, pid_t child, int prio = dasynq::DEFAULT_PRIORITY) noexcept