root/lib/common/tests/scheduler/pcmk__update_recheck_time_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. assert_recheck
  2. null_scheduler
  3. too_early
  4. first_time
  5. earlier_time
  6. later_time

   1 /*
   2  * Copyright 2024 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <stdio.h>          // NULL
  13 #include <sys/types.h>      // time_t
  14 
  15 #include <crm/common/scheduler.h>
  16 #include <crm/common/scheduler_internal.h>
  17 #include <crm/common/unittest_internal.h>
  18 
  19 static void
  20 assert_recheck(time_t now_time, time_t orig_time, time_t update_time,
     /* [previous][next][first][last][top][bottom][index][help] */
  21                time_t expected_time, const char *reason)
  22 {
  23     pcmk_scheduler_t *scheduler = pcmk_new_scheduler();
  24 
  25     scheduler->priv->now = pcmk__copy_timet(now_time);
  26     scheduler->priv->recheck_by = orig_time;
  27     pcmk__update_recheck_time(update_time, scheduler, reason);
  28     assert_int_equal(scheduler->priv->recheck_by, expected_time);
  29     pcmk_free_scheduler(scheduler);
  30 }
  31 
  32 // A NULL scheduler argument is invalid and should assert
  33 static void
  34 null_scheduler(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36     pcmk__assert_asserts(pcmk__update_recheck_time(0, NULL, "reasons"));
  37 }
  38 
  39 // Do not update recheck time if new value is before or equal to "now"
  40 static void
  41 too_early(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43     // Recheck time is initially unset
  44     assert_recheck(1423548000, 0, 1423547900, 0, NULL);
  45     assert_recheck(1423548000, 0, 1423548000, 0, NULL);
  46 
  47     // Recheck time is initially set
  48     assert_recheck(1423548000, 1423548100, 1423547900, 1423548100, NULL);
  49     assert_recheck(1423548000, 1423548100, 1423548000, 1423548100, NULL);
  50 }
  51 
  52 // Update recheck time if the existing value is 0
  53 static void
  54 first_time(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56     // This also tests that a NULL reason does not crash
  57     assert_recheck(1423548000, 0, 1423548100, 1423548100, NULL);
  58 }
  59 
  60 // Update recheck time if new value is earlier than the existing one
  61 static void
  62 earlier_time(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64     assert_recheck(1423548000, 1423548500, 1423548200, 1423548200, "reasons");
  65 }
  66 
  67 // Do not update recheck time if new value is later than the existing one
  68 static void
  69 later_time(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71     assert_recheck(1423548000, 1423548500, 1423548600, 1423548500, "reasons");
  72 }
  73 
  74 PCMK__UNIT_TEST(NULL, NULL,
  75                 cmocka_unit_test(null_scheduler),
  76                 cmocka_unit_test(too_early),
  77                 cmocka_unit_test(first_time),
  78                 cmocka_unit_test(earlier_time),
  79                 cmocka_unit_test(later_time))

/* [previous][next][first][last][top][bottom][index][help] */