summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2018-06-14 15:38:46 +0300
committerNick Mathewson <nickm@torproject.org>2018-07-17 15:57:46 -0400
commit2e8d4139a77111d5b24726e970744378dcb92baa (patch)
treea55f13fd900683a6f3a07659d7ae798c8db8b13a /src/test
parent5fb6f656dfad3ddb178b76448742bfc3e2e834da (diff)
downloadtor-2e8d4139a77111d5b24726e970744378dcb92baa.tar.gz
tor-2e8d4139a77111d5b24726e970744378dcb92baa.zip
Fix up some unittests by being more careful with the local time.
Now that the rev counter depends on the local time, we need to be more careful in the unittests. Some unittests were breaking because they were using consensus values from 1985, but they were not updating the local time appropriately. That was causing the OPE module to complain that it was trying to encrypt insanely large values.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_hs_common.c3
-rw-r--r--src/test/test_hs_service.c20
2 files changed, 20 insertions, 3 deletions
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c
index 6296a709dc..47a021312a 100644
--- a/src/test/test_hs_common.c
+++ b/src/test/test_hs_common.c
@@ -1361,7 +1361,8 @@ run_reachability_scenario(const reachability_cfg_t *cfg, int num_scenario)
mock_service_ns->sr_info.previous_srv = cfg->service_previous_srv;
/* Initialize a service to get keys. */
- service = helper_init_service(time(NULL));
+ update_approx_time(mock_service_ns->valid_after);
+ service = helper_init_service(mock_service_ns->valid_after+1);
/*
* === Client setup ===
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 684ac98f42..e328ca5bdc 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -1042,7 +1042,7 @@ static void
test_rotate_descriptors(void *arg)
{
int ret;
- time_t next_rotation_time, now = time(NULL);
+ time_t next_rotation_time, now;
hs_service_t *service;
hs_service_descriptor_t *desc_next;
@@ -1066,6 +1066,9 @@ test_rotate_descriptors(void *arg)
tt_int_op(ret, OP_EQ, 0);
voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
+ update_approx_time(mock_ns.valid_after+1);
+ now = mock_ns.valid_after+1;
+
/* Create a service with a default descriptor and state. It's added to the
* global map. */
service = helper_create_service();
@@ -1104,6 +1107,9 @@ test_rotate_descriptors(void *arg)
tt_int_op(ret, OP_EQ, 0);
voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
+ update_approx_time(mock_ns.valid_after+1);
+ now = mock_ns.valid_after+1;
+
/* Note down what to expect for the next rotation time which is 01:00 + 23h
* meaning 00:00:00. */
next_rotation_time = mock_ns.valid_after + (23 * 60 * 60);
@@ -1166,6 +1172,9 @@ test_build_update_descriptors(void *arg)
tt_int_op(ret, OP_EQ, 0);
voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
+ update_approx_time(mock_ns.valid_after+1);
+ now = mock_ns.valid_after+1;
+
/* Create a service without a current descriptor to trigger a build. */
service = helper_create_service();
tt_assert(service);
@@ -1307,6 +1316,9 @@ test_build_update_descriptors(void *arg)
&mock_ns.fresh_until);
tt_int_op(ret, OP_EQ, 0);
+ update_approx_time(mock_ns.valid_after+1);
+ now = mock_ns.valid_after+1;
+
/* Create a service without a current descriptor to trigger a build. */
service = helper_create_service();
tt_assert(service);
@@ -1361,7 +1373,7 @@ static void
test_upload_descriptors(void *arg)
{
int ret;
- time_t now = time(NULL);
+ time_t now;
hs_service_t *service;
(void) arg;
@@ -1380,6 +1392,10 @@ test_upload_descriptors(void *arg)
ret = parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC",
&mock_ns.fresh_until);
tt_int_op(ret, OP_EQ, 0);
+ voting_schedule_recalculate_timing(get_options(), mock_ns.valid_after);
+
+ update_approx_time(mock_ns.valid_after+1);
+ now = mock_ns.valid_after+1;
/* Create a service with no descriptor. It's added to the global map. */
service = hs_service_new(get_options());