[tor-commits] [tor/master] Test the easiest cases of consdiffmgr_cleanup.

nickm at torproject.org nickm at torproject.org
Mon Apr 24 15:05:42 UTC 2017


commit 35f6b678abaa298857e6b5cef187813c4c161571
Author: Nick Mathewson <nickm at torproject.org>
Date:   Sat Apr 15 10:59:05 2017 -0400

    Test the easiest cases of consdiffmgr_cleanup.
    
    One more to go: deleting the old diffs.
---
 src/or/consdiffmgr.c        |  2 +-
 src/or/consdiffmgr.h        |  1 +
 src/test/test_consdiffmgr.c | 91 +++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 89 insertions(+), 5 deletions(-)

diff --git a/src/or/consdiffmgr.c b/src/or/consdiffmgr.c
index 27c95e8..df9c5b9 100644
--- a/src/or/consdiffmgr.c
+++ b/src/or/consdiffmgr.c
@@ -92,7 +92,7 @@ cdm_cache_init(void)
  * Helper: return the consensus_cache_t * that backs this manager,
  * initializing it if needed.
  */
-static consensus_cache_t *
+STATIC consensus_cache_t *
 cdm_cache_get(void)
 {
   if (PREDICT_UNLIKELY(cons_diff_cache == NULL)) {
diff --git a/src/or/consdiffmgr.h b/src/or/consdiffmgr.h
index 474876e..2b3cee2 100644
--- a/src/or/consdiffmgr.h
+++ b/src/or/consdiffmgr.h
@@ -35,6 +35,7 @@ void consdiffmgr_configure(const consdiff_cfg_t *cfg);
 void consdiffmgr_free_all(void);
 
 #ifdef CONSDIFFMGR_PRIVATE
+STATIC consensus_cache_t *cdm_cache_get(void);
 STATIC consensus_cache_entry_t *cdm_cache_lookup_consensus(
                           consensus_flavor_t flavor, time_t valid_after);
 #endif
diff --git a/src/test/test_consdiffmgr.c b/src/test/test_consdiffmgr.c
index fc21369..624c772 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
 };
 





More information about the tor-commits mailing list