Skip to content

Commit

Permalink
Add test for expiring acknowledgement
Browse files Browse the repository at this point in the history
This adds a test that checks if the acknowledgement expiry event does
its work.

It starts by removing all events from the event queue. We then run the
command, with expiration set in two seconds. After waiting three
seconds, we process a single event (we should have only one event in the
queue at this point). After processing the event, the acknowledgement
should be gone.
  • Loading branch information
roelvanmeer committed Sep 6, 2022
1 parent f6df564 commit 6c26ca5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion t-tap/test_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ void test_host_commands(void)
int pre = 0, prev_comment_id = next_comment_id;
unsigned int prev_downtime_id;
time_t check_time = 0;
time_t current_time = 0;
char *cmdstr = NULL;
scheduled_downtime *downtime = NULL;
target_host = find_host(host_name);
Expand Down Expand Up @@ -522,6 +523,17 @@ void test_host_commands(void)
ok(!target_host->problem_has_been_acknowledged, "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE with past end_time doesn't acknowledge a host problem");
target_host->current_state = STATE_UP;

clear_event_queue();
target_host->current_state = STATE_DOWN;
time(&current_time);
nm_asprintf(&cmdstr, "[1234567890] ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;host1;2;0;0;%llu;myself;expire in two seconds", (unsigned long long int)current_time+2);
ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: ACKNOWLEDGE_HOST_PROBLEM_EXPIRE");
ok(target_host->problem_has_been_acknowledged, "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE acknowledgement present before event");
sleep(3);
event_poll();
ok(!target_host->problem_has_been_acknowledged, "ACKNOWLEDGE_HOST_PROBLEM_EXPIRE acknowledgement gone after event");
free(cmdstr);

ok(CMD_ERROR_OK == process_external_command1("[1234567890] DISABLE_HOST_EVENT_HANDLER;host1"), "core command: DISABLE_HOST_EVENT_HANDLER");
ok(!target_host->event_handler_enabled, "DISABLE_HOST_EVENT_HANDLER disables event handler for a host");

Expand Down Expand Up @@ -683,7 +695,7 @@ void test_core_commands(void)
int main(int /*@unused@*/ argc, char /*@unused@*/ **arv)
{
const char *test_config_file = TESTDIR "naemon.cfg";
plan_tests(513);
plan_tests(516);
init_event_queue();

config_file_dir = nspath_absolute_dirname(test_config_file, NULL);
Expand Down

0 comments on commit 6c26ca5

Please sign in to comment.