aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTaylor Yu <catalyst@torproject.org>2019-03-28 17:45:49 -0500
committerDavid Goulet <dgoulet@torproject.org>2019-06-11 11:59:30 -0400
commit0bce0c339d5f4c6ddeb90c21502a9716fb6cd17a (patch)
treeb578ef01c6480ac9bb1eca3fd239e6fd79dd53ed /src/test
parenta8c0f4ddfe3f0a63bd499959c8d921346aa9766e (diff)
downloadtor-0bce0c339d5f4c6ddeb90c21502a9716fb6cd17a.tar.gz
tor-0bce0c339d5f4c6ddeb90c21502a9716fb6cd17a.zip
Rework origin circuit tracking to use pubsub
Part of ticket 29976.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_btrack.c24
-rw-r--r--src/test/test_circuitstats.c2
-rw-r--r--src/test/test_controller_events.c11
-rw-r--r--src/test/test_helpers.c2
4 files changed, 24 insertions, 15 deletions
diff --git a/src/test/test_btrack.c b/src/test/test_btrack.c
index fef1da4842..9e5d0d0723 100644
--- a/src/test/test_btrack.c
+++ b/src/test/test_btrack.c
@@ -31,10 +31,19 @@ send_status(const orconn_status_msg_t *msg_in)
}
static void
+send_chan(const ocirc_chan_msg_t *msg_in)
+{
+ ocirc_chan_msg_t *msg = tor_malloc(sizeof(*msg));
+
+ *msg = *msg_in;
+ ocirc_chan_publish(msg);
+}
+
+static void
test_btrack_launch(void *arg)
{
orconn_state_msg_t conn;
- ocirc_event_msg_t circ;
+ ocirc_chan_msg_t circ;
(void)arg;
conn.gid = 1;
@@ -48,12 +57,11 @@ test_btrack_launch(void *arg)
expect_no_log_msg_containing("ORCONN BEST_");
teardown_capture_of_logs();
- circ.type = OCIRC_MSGTYPE_CHAN;
- circ.u.chan.chan = 1;
- circ.u.chan.onehop = true;
+ circ.chan = 1;
+ circ.onehop = true;
setup_full_capture_of_logs(LOG_DEBUG);
- ocirc_event_publish(&circ);
+ send_chan(&circ);
expect_log_msg_containing("ORCONN LAUNCH chan=1 onehop=1");
expect_log_msg_containing("ORCONN BEST_ANY state -1->1 gid=1");
teardown_capture_of_logs();
@@ -67,11 +75,11 @@ test_btrack_launch(void *arg)
expect_no_log_msg_containing("ORCONN BEST_");
teardown_capture_of_logs();
- circ.u.chan.chan = 2;
- circ.u.chan.onehop = false;
+ circ.chan = 2;
+ circ.onehop = false;
setup_full_capture_of_logs(LOG_DEBUG);
- ocirc_event_publish(&circ);
+ send_chan(&circ);
expect_log_msg_containing("ORCONN LAUNCH chan=2 onehop=0");
expect_log_msg_containing("ORCONN BEST_AP state -1->1 gid=2");
teardown_capture_of_logs();
diff --git a/src/test/test_circuitstats.c b/src/test/test_circuitstats.c
index 2a09622f09..9bfaabeb2f 100644
--- a/src/test/test_circuitstats.c
+++ b/src/test/test_circuitstats.c
@@ -197,7 +197,7 @@ test_circuitstats_hoplen(void *arg)
}
#define TEST_CIRCUITSTATS(name, flags) \
- { #name, test_##name, (flags), NULL, NULL }
+ { #name, test_##name, (flags), &helper_pubsub_setup, NULL }
struct testcase_t circuitstats_tests[] = {
TEST_CIRCUITSTATS(circuitstats_hoplen, TT_FORK),
diff --git a/src/test/test_controller_events.c b/src/test/test_controller_events.c
index 14fe4fd661..a8967bba50 100644
--- a/src/test/test_controller_events.c
+++ b/src/test/test_controller_events.c
@@ -417,13 +417,12 @@ send_orconn_state(const orconn_state_msg_t *msg_in, uint8_t state)
static void
send_ocirc_chan(uint32_t gid, uint64_t chan, bool onehop)
{
- ocirc_event_msg_t msg;
+ ocirc_chan_msg_t *msg = tor_malloc(sizeof(*msg));
- msg.type = OCIRC_MSGTYPE_CHAN;
- msg.u.chan.gid = gid;
- msg.u.chan.chan = chan;
- msg.u.chan.onehop = onehop;
- ocirc_event_publish(&msg);
+ msg->gid = gid;
+ msg->chan = chan;
+ msg->onehop = onehop;
+ ocirc_chan_publish(msg);
}
static void
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c
index e856dc6cca..b4389f2d17 100644
--- a/src/test/test_helpers.c
+++ b/src/test/test_helpers.c
@@ -338,6 +338,8 @@ helper_setup_pubsub(const struct testcase_t *testcase)
dispatcher = pubsub_builder_finalize(builder, NULL);
tor_assert(dispatcher);
dispatch_set_alert_fn(dispatcher, chan, alertfn_immediate, NULL);
+ chan = get_channel_id("ocirc");
+ dispatch_set_alert_fn(dispatcher, chan, alertfn_immediate, NULL);
return dispatcher;
}