aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_consdiffmgr.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-04-15 10:05:10 -0400
committerNick Mathewson <nickm@torproject.org>2017-04-24 10:59:25 -0400
commitd418f28cb5cd175f224768fe214e2e2c1bc2b413 (patch)
treed0de015cc843f6c83156202cc4d451c4bc14345e /src/test/test_consdiffmgr.c
parentb9c2f135bd0d0bb9f0b1d40cda794ead912f75d0 (diff)
downloadtor-d418f28cb5cd175f224768fe214e2e2c1bc2b413.tar.gz
tor-d418f28cb5cd175f224768fe214e2e2c1bc2b413.zip
consdiffmgr test: survive failures to compute a diff.
Diffstat (limited to 'src/test/test_consdiffmgr.c')
-rw-r--r--src/test/test_consdiffmgr.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/test/test_consdiffmgr.c b/src/test/test_consdiffmgr.c
index f550482304..1a666cc85b 100644
--- a/src/test/test_consdiffmgr.c
+++ b/src/test/test_consdiffmgr.c
@@ -353,6 +353,45 @@ test_consdiffmgr_diff_rules(void *arg)
#undef N
}
+static void
+test_consdiffmgr_diff_failure(void *arg)
+{
+ (void)arg;
+ MOCK(cpuworker_queue_work, mock_cpuworker_queue_work);
+
+ /* We're going to make sure that if we have a bogus request where
+ * we can't actually compute a diff, the world must not end. */
+ networkstatus_t *ns1 = NULL;
+ networkstatus_t *ns2 = NULL;
+ int r;
+
+ ns1 = fake_ns_new(FLAV_NS, approx_time()-100);
+ ns2 = fake_ns_new(FLAV_NS, approx_time()-50);
+ r = consdiffmgr_add_consensus("foo bar baz\n", ns1);
+ tt_int_op(r, OP_EQ, 0);
+ // We refuse to compute a diff to or from a line holding only a single dot.
+ // We can add it here, though.
+ r = consdiffmgr_add_consensus("foo bar baz\n.\n.\n", ns2);
+ tt_int_op(r, OP_EQ, 0);
+
+ consdiffmgr_rescan();
+ tt_ptr_op(NULL, OP_NE, fake_cpuworker_queue);
+ setup_capture_of_logs(LOG_WARN);
+ tt_int_op(1, OP_EQ, smartlist_len(fake_cpuworker_queue));
+ tt_int_op(0, OP_EQ, mock_cpuworker_run_work());
+ expect_single_log_msg_containing("one of the lines to be added is \".\".");
+ mock_clean_saved_logs();
+ mock_cpuworker_handle_replies();
+ expect_single_log_msg_containing("Worker was unable to compute consensus "
+ "diff from ");
+
+ done:
+ teardown_capture_of_logs();
+ UNMOCK(cpuworker_queue_work);
+ networkstatus_vote_free(ns1);
+ networkstatus_vote_free(ns2);
+}
+
#define TEST(name) \
{ #name, test_consdiffmgr_ ## name , TT_FORK, &setup_diffmgr, NULL }
@@ -360,6 +399,7 @@ struct testcase_t consdiffmgr_tests[] = {
TEST(add),
TEST(make_diffs),
TEST(diff_rules),
+ TEST(diff_failure),
// XXXX Test: deleting consensuses for being too old
// XXXX Test: deleting diffs for not being to most recent consensus
@@ -367,7 +407,6 @@ struct testcase_t consdiffmgr_tests[] = {
// XXXX Test: Objects with bad iso time are not cleaned.
// XXXX Test: Failure to open cache???
- // XXXX Test: failure to create consensus diff.
END_OF_TESTCASES
};