Fix smooth recovery test.
authorDavin McCall <davmac@davmac.org>
Tue, 16 Jan 2018 17:59:36 +0000 (17:59 +0000)
committerDavin McCall <davmac@davmac.org>
Tue, 16 Jan 2018 17:59:36 +0000 (17:59 +0000)
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.

src/tests/Makefile
src/tests/proctests.cc
src/tests/test-bpsys.cc
src/tests/test-includes/dinit.h

index 9f94055047a20331e4ddb91276cde1c9a1fb7a2b..05d2a2d3cfa0803094f2ae400b2d104e3db514f7 100644 (file)
@@ -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 $@
index f193dbed9eec068bdd27ac34dd63cea190a633b0..9e8273909c1cf734f40f9ed611a0bb7ba231c5c4 100644 (file)
@@ -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);
 }
 
index a117d3ae0fa45a18900e8117dee5d2fec21697de..e02d717c897729c00d717c5e0bcb53e8a45b380c 100644 (file)
@@ -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)
 {
index 521f68ff195493f99e401af87e6a64a66c9c77e8..ef945cae1f59692f83fc52a8117536fb4d7625a9 100644 (file)
@@ -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