Skip to content

Commit 0f92646

Browse files
tobastfwsmit
authored andcommitted
Test notification age update at turn of second
1 parent 73c54bd commit 0f92646

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/queues.c

+42
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,47 @@ TEST test_datachange_endless_agethreshold(void)
498498
PASS();
499499
}
500500

501+
TEST test_datachange_agethreshold_at_second(void)
502+
{
503+
settings.show_age_threshold = S2US(5);
504+
505+
queues_init();
506+
507+
const gint64 NOTIF_DELTA = 200;
508+
509+
gint64 cur_time = 500*1000; // T = 0.5s
510+
struct notification *n = test_notification("n0", 0);
511+
n->timestamp = cur_time;
512+
queues_notification_insert(n);
513+
514+
cur_time += NOTIF_DELTA;
515+
n = test_notification("n1", 0);
516+
n->timestamp = cur_time;
517+
queues_notification_insert(n);
518+
519+
queues_update(STATUS_NORMAL, cur_time);
520+
521+
// The next update should be when age must be first displayed, at T=5.5s
522+
ASSERTm("Age threshold is activated, first wakeup should be at 5.5s",
523+
cur_time + queues_get_next_datachange(cur_time) == S2US(5) + 500000);
524+
525+
const int NB_MICROSECS = 6;
526+
const gint64 MICROSECS[] = {
527+
0, 10, NOTIF_DELTA, NOTIF_DELTA + 1, 124131, S2US(1)-1
528+
};
529+
for(gint64 base_time = S2US(5); base_time <= S2US(7); base_time += S2US(1)) {
530+
for(int musec_id = 0; musec_id < NB_MICROSECS; ++musec_id) {
531+
cur_time = base_time + MICROSECS[musec_id];
532+
gint64 next_wakeup = cur_time + queues_get_next_datachange(cur_time);
533+
ASSERTm("Age threshold is activated, next wakeup should be at next turn of second",
534+
next_wakeup == base_time + S2US(1));
535+
}
536+
}
537+
538+
queues_teardown();
539+
PASS();
540+
}
541+
501542
TEST test_datachange_queues(void)
502543
{
503544
queues_init();
@@ -1041,6 +1082,7 @@ SUITE(suite_queues)
10411082
RUN_TEST(test_datachange_beginning_empty);
10421083
RUN_TEST(test_datachange_endless);
10431084
RUN_TEST(test_datachange_endless_agethreshold);
1085+
RUN_TEST(test_datachange_agethreshold_at_second);
10441086
RUN_TEST(test_datachange_queues);
10451087
RUN_TEST(test_datachange_ttl);
10461088
RUN_TEST(test_queue_history_clear);

0 commit comments

Comments
 (0)