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 7, 2022
1 parent 2d2e3d1 commit 9e0bb48
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion t-tap/test_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,16 @@ 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;
nm_asprintf(&cmdstr, "[1234567890] ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;host1;2;0;0;%llu;myself;expire in two seconds", (unsigned long long int)time(NULL)+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 +693,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 9e0bb48

Please sign in to comment.