From 9e0bb482f1d56616d3ef256609030faf6c03161d Mon Sep 17 00:00:00 2001 From: Roel van Meer Date: Tue, 6 Sep 2022 22:27:25 +0200 Subject: [PATCH] Add test for expiring acknowledgement 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. --- t-tap/test_commands.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/t-tap/test_commands.c b/t-tap/test_commands.c index fe004053..4377efba 100644 --- a/t-tap/test_commands.c +++ b/t-tap/test_commands.c @@ -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"); @@ -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);