Skip to content

Commit

Permalink
Test: propagate failure to dependent when restart threshold exceeded
Browse files Browse the repository at this point in the history
Test for #249
  • Loading branch information
davmac314 committed Oct 17, 2023
1 parent 822cb00 commit eaf24da
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/tests/proctests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,75 @@ void test_proc_term_restart4()
sset.remove_service(&p);
}

// Failure to restart should propagate to dependent
void test_proc_term_restart_fail()
{
using namespace std;

service_set sset;

ha_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 {&sset, "testproc", std::move(command), command_offsets, depends};
init_service_defaults(p);
p.set_auto_restart(true);

sset.add_service(&p);

service_record p_dpt1 {&sset, "dpt1", service_type_t::INTERNAL, {{ &p, REG }}};
p_dpt1.set_auto_restart(true);
sset.add_service(&p_dpt1);

service_record p_dpt2 {&sset, "dpt2", service_type_t::INTERNAL, {{ &p_dpt1, WAITS }}};
sset.add_service(&p_dpt2);

p_dpt2.start();
sset.process_queues();

for (int i = 0; i < 3; ++i) {

assert(p.get_state() == service_state_t::STARTING);
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);

base_process_service_test::handle_exit(&p, 0);
sset.process_queues();

// Starting, restart timer should be armed:
assert(p.get_state() == service_state_t::STARTING);
assert(event_loop.active_timers.size() == 1);

event_loop.advance_time(default_restart_interval);

}

assert(p.get_state() == service_state_t::STARTING);
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);

// There should be no attempt to restart this time:

base_process_service_test::handle_exit(&p, 0);
sset.process_queues();

assert(event_loop.active_timers.size() == 0);
assert(p.get_state() == service_state_t::STOPPED);
assert(p_dpt1.get_state() == service_state_t::STOPPED);

sset.remove_service(&p_dpt2);
sset.remove_service(&p_dpt1);
sset.remove_service(&p);
}

// Termination via stop request
void test_term_via_stop()
{
Expand Down Expand Up @@ -2423,6 +2492,7 @@ int main(int argc, char **argv)
RUN_TEST(test_proc_term_restart2, " ");
RUN_TEST(test_proc_term_restart3, " ");
RUN_TEST(test_proc_term_restart4, " ");
RUN_TEST(test_proc_term_restart_fail, "");
RUN_TEST(test_term_via_stop, " ");
RUN_TEST(test_term_via_stop2, " ");
RUN_TEST(test_term_via_stop3, " ");
Expand Down

0 comments on commit eaf24da

Please sign in to comment.