aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_shared_random.c
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-03-13 15:27:48 +1000
committerteor <teor@torproject.org>2019-03-13 15:29:46 +1000
commita9c3101e2140ceacc47498a8d15c8b54ad2616c5 (patch)
tree825702a3165c21c2ebb587536176f9c5bd35fb56 /src/test/test_shared_random.c
parentdfc3e552a3b7617add0bd576a5c34dca59f42649 (diff)
downloadtor-a9c3101e2140ceacc47498a8d15c8b54ad2616c5.tar.gz
tor-a9c3101e2140ceacc47498a8d15c8b54ad2616c5.zip
test/sr: Clear SRVs after init, and before setup
Part of 29706.
Diffstat (limited to 'src/test/test_shared_random.c')
-rw-r--r--src/test/test_shared_random.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index 991d73128e..6324fa68b5 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -61,6 +61,9 @@ init_authority_state(void)
* the phase we are currently in which uses "now" as the starting
* timestamp. Delete it before we do any testing below. */
sr_state_delete_commits();
+ /* It's also possible that a current SRV has been generated, if we are at
+ * state transition time. But let's just forget about that SRV. */
+ sr_state_clean_srvs();
done:
UNMOCK(get_my_v3_authority_cert);
@@ -545,22 +548,24 @@ test_encoding(void *arg)
;
}
-/** Setup some SRVs in our SR state. If <b>also_current</b> is set, then set
- * both current and previous SRVs.
- * Helper of test_vote() and test_sr_compute_srv().
+/** Setup some SRVs in our SR state.
+ * If <b>also_current</b> is set, then set both current and previous SRVs.
+ * Otherwise, just set the previous SRV. (And clear the current SRV.)
+ *
* You must call sr_state_free_all() to free the state at the end of each test
* function (on pass or fail). */
static void
test_sr_setup_srv(int also_current)
{
+ /* Clear both SRVs before starting. */
+ sr_state_clean_srvs();
+
sr_srv_t *srv = tor_malloc_zero(sizeof(sr_srv_t));
srv->num_reveals = 42;
memcpy(srv->value,
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
sizeof(srv->value));
- /* sr_state_set_previous_srv() does not free() the old previous srv. */
- state_del_previous_srv();
sr_state_set_previous_srv(srv);
if (also_current) {
@@ -570,8 +575,6 @@ test_sr_setup_srv(int also_current)
"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
sizeof(srv->value));
- /* sr_state_set_previous_srv() does not free() the old current srv. */
- state_del_current_srv();
sr_state_set_current_srv(srv);
}
}