aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_consdiffmgr.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-04-15 10:59:05 -0400
committerNick Mathewson <nickm@torproject.org>2017-04-24 10:59:25 -0400
commit35f6b678abaa298857e6b5cef187813c4c161571 (patch)
tree976e26feb06bf563d358172a3821b4481a0bd0c5 /src/test/test_consdiffmgr.c
parent1fade372872130dca4057845eeb0a303b0ac52f6 (diff)
downloadtor-35f6b678abaa298857e6b5cef187813c4c161571.tar.gz
tor-35f6b678abaa298857e6b5cef187813c4c161571.zip
Test the easiest cases of consdiffmgr_cleanup.
One more to go: deleting the old diffs.
Diffstat (limited to 'src/test/test_consdiffmgr.c')
-rw-r--r--src/test/test_consdiffmgr.c91
1 files changed, 87 insertions, 4 deletions
diff --git a/src/test/test_consdiffmgr.c b/src/test/test_consdiffmgr.c
index fc21369e18..624c772b8a 100644
--- a/src/test/test_consdiffmgr.c
+++ b/src/test/test_consdiffmgr.c
@@ -428,6 +428,89 @@ test_consdiffmgr_diff_failure(void *arg)
networkstatus_vote_free(ns2);
}
+static void
+test_consdiffmgr_cleanup_old(void *arg)
+{
+ (void)arg;
+ config_line_t *labels = NULL;
+ consensus_cache_entry_t *ent = NULL;
+ consensus_cache_t *cache = cdm_cache_get(); // violate abstraction barrier
+
+ /* This item will be will be cleanable because it has a valid-after
+ * time far in the past. */
+ config_line_prepend(&labels, "document-type", "confribble-blarg");
+ config_line_prepend(&labels, "consensus-valid-after",
+ "1980-10-10T10:10:10");
+ ent = consensus_cache_add(cache, labels, (const uint8_t*)"Foo", 3);
+ tt_assert(ent);
+ consensus_cache_entry_decref(ent);
+
+ setup_capture_of_logs(LOG_DEBUG);
+ tt_int_op(1, OP_EQ, consdiffmgr_cleanup());
+ expect_log_msg_containing("Deleting entry because its consensus-valid-"
+ "after value (1980-10-10T10:10:10) was too old");
+
+ done:
+ teardown_capture_of_logs();
+ config_free_lines(labels);
+}
+
+static void
+test_consdiffmgr_cleanup_bad_valid_after(void *arg)
+{
+ /* This will seem cleanable, but isn't, because its valid-after time is
+ * misformed. */
+
+ (void)arg;
+ config_line_t *labels = NULL;
+ consensus_cache_entry_t *ent = NULL;
+ consensus_cache_t *cache = cdm_cache_get(); // violate abstraction barrier
+
+ config_line_prepend(&labels, "document-type", "consensus");
+ config_line_prepend(&labels, "consensus-valid-after",
+ "whan that aprille with his shoures soote"); // (~1385?)
+ ent = consensus_cache_add(cache, labels, (const uint8_t*)"Foo", 3);
+ tt_assert(ent);
+ consensus_cache_entry_decref(ent);
+
+ setup_capture_of_logs(LOG_DEBUG);
+ tt_int_op(0, OP_EQ, consdiffmgr_cleanup());
+ expect_log_msg_containing("Ignoring entry because its consensus-valid-"
+ "after value (\"whan that aprille with his "
+ "shoures soote\") was unparseable");
+
+ done:
+ teardown_capture_of_logs();
+ config_free_lines(labels);
+}
+
+static void
+test_consdiffmgr_cleanup_no_valid_after(void *arg)
+{
+ (void)arg;
+ config_line_t *labels = NULL;
+ consensus_cache_entry_t *ent = NULL;
+ consensus_cache_t *cache = cdm_cache_get(); // violate abstraction barrier
+
+ /* This item will be will be uncleanable because it has no recognized
+ * valid-after. */
+ config_line_prepend(&labels, "document-type", "consensus");
+ config_line_prepend(&labels, "confrooble-voolid-oofter",
+ "2010-10-10T09:08:07");
+ ent = consensus_cache_add(cache, labels, (const uint8_t*)"Foo", 3);
+ tt_assert(ent);
+ consensus_cache_entry_decref(ent);
+
+ setup_capture_of_logs(LOG_DEBUG);
+ tt_int_op(0, OP_EQ, consdiffmgr_cleanup());
+ expect_log_msg_containing("Ignoring entry because it had no consensus-"
+ "valid-after label");
+
+ done:
+ teardown_capture_of_logs();
+ config_free_lines(labels);
+}
+
#define TEST(name) \
{ #name, test_consdiffmgr_ ## name , TT_FORK, &setup_diffmgr, NULL }
@@ -439,11 +522,11 @@ struct testcase_t consdiffmgr_tests[] = {
TEST(make_diffs),
TEST(diff_rules),
TEST(diff_failure),
+ TEST(cleanup_old),
+ TEST(cleanup_bad_valid_after),
+ TEST(cleanup_no_valid_after),
+ //TEST(cleanup_old_diffs),
- // XXXX Test: deleting consensuses for being too old
- // XXXX Test: deleting diffs for not being to most recent consensus
- // XXXX Test: Objects of unrecognized doctype are not cleaned.
- // XXXX Test: Objects with bad iso time are not cleaned.
END_OF_TESTCASES
};