Skip to content
Snippets Groups Projects
Commit 4de2ab11 authored by Jan Kadlec's avatar Jan Kadlec
Browse files

unittests: Extented zone timer tests.

parent 2be98305
Branches
Tags
No related merge requests found
......@@ -353,3 +353,4 @@ tests/zone_events.c
tests/zone_update.c
tests/zonedb.c
tests/ztree.c
tests/zone_timers.c
......@@ -46,6 +46,7 @@ check_PROGRAMS = \
worker_queue \
zone_events \
zone_update \
zone_timers \
namedb
check-compile-only: $(check_PROGRAMS)
......
......@@ -36,11 +36,21 @@ int main(int argc, char *argv[])
// Temporary DB identifier.
char dbid_buf[] = "/tmp/timerdb.XXXXXX";
const char *dbid = mkdtemp(dbid_buf);
// Mockup zone.
conf_zone_t zone_conf = { .name = "test." };
zone_t *zone = zone_new(&zone_conf);
assert(zone);
// Mockup zones.
conf_zone_t zone_conf = { .name = "test1." };
zone_t *zone_1 = zone_new(&zone_conf);
zone_conf.name = "test2.";
zone_t *zone_2 = zone_new(&zone_conf);
assert(zone_1 && zone_2);
// Mockup zonedb.
knot_zonedb_t *zone_db = knot_zonedb_new(2);
assert(zone_db);
int ret = knot_zonedb_insert(zone_db, zone_1);
assert(ret == KNOT_EOK);
ret = knot_zonedb_insert(zone_db, zone_2);
assert(ret == KNOT_EOK);
knot_namedb_t *db = open_timers_db(dbid);
ok(db != NULL, "zone timers: create");
......@@ -52,25 +62,54 @@ int main(int argc, char *argv[])
const time_t FLUSH_TIME = now + FLUSH_SLIP;
// Refresh, expire and flush are the permanent events for now.
zone_events_schedule_at(zone, ZONE_EVENT_REFRESH, REFRESH_TIME);
zone_events_schedule_at(zone, ZONE_EVENT_EXPIRE, EXPIRE_TIME);
zone_events_schedule_at(zone, ZONE_EVENT_FLUSH, FLUSH_TIME);
zone_events_schedule_at(zone_1, ZONE_EVENT_REFRESH, REFRESH_TIME);
zone_events_schedule_at(zone_1, ZONE_EVENT_EXPIRE, EXPIRE_TIME);
zone_events_schedule_at(zone_1, ZONE_EVENT_FLUSH, FLUSH_TIME);
// Write the timers.
int ret = write_zone_timers(db, zone);
ret = write_zone_timers(db, zone_1);
ok(ret == KNOT_EOK, "zone timers: write");
// Read the timers.
time_t timers[ZONE_EVENT_COUNT];
ret = read_zone_timers(db, zone, timers);
ret = read_zone_timers(db, zone_1, timers);
ok(ret == KNOT_EOK &&
timers[ZONE_EVENT_REFRESH] == REFRESH_TIME &&
timers[ZONE_EVENT_EXPIRE] == EXPIRE_TIME &&
timers[ZONE_EVENT_FLUSH] == FLUSH_TIME, "zone timers: read");
timers[ZONE_EVENT_FLUSH] == FLUSH_TIME, "zone timers: read set");
// Sweep and read again - timers should stay the same.
int s_ret = sweep_timer_db(db, zone_db);
if (s_ret == KNOT_EOK) {
ret = read_zone_timers(db, zone_1, timers);
}
ok(s_ret == KNOT_EOK && ret == KNOT_EOK &&
timers[ZONE_EVENT_REFRESH] == REFRESH_TIME &&
timers[ZONE_EVENT_EXPIRE] == EXPIRE_TIME &&
timers[ZONE_EVENT_FLUSH] == FLUSH_TIME, "zone timers: sweep no-op");
// Read timers for unset zone.
const time_t empty_timers[ZONE_EVENT_COUNT] = { '\0' };
ret = read_zone_timers(db, zone_2, timers);
ok(ret == KNOT_EOK &&
memcmp(timers, empty_timers, sizeof(timers)) == 0, "zone timers: read unset");
// Remove first zone from db and sweep.
ret = knot_zonedb_del(zone_db, zone_1->name);
assert(ret == KNOT_EOK);
s_ret = sweep_timer_db(db, zone_db);
if (s_ret == KNOT_EOK) {
ret = read_zone_timers(db, zone_1, timers);
}
ok(s_ret == KNOT_EOK && ret == KNOT_EOK &&
memcmp(timers, empty_timers, sizeof(timers)) == 0, "zone timers: sweep");
// Clean up.
zone->conf = NULL;
zone_free(&zone);
zone_1->conf = NULL;
zone_2->conf = NULL;
zone_free(&zone_1);
zone_free(&zone_2);
close_timers_db(db);
return EXIT_SUCCESS;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment