[tor-commits] [tor/master] Fix up some unittests by being more careful with the local time.

nickm at torproject.org nickm at torproject.org
Tue Jul 17 20:19:40 UTC 2018


commit 2e8d4139a77111d5b24726e970744378dcb92baa
Author: George Kadianakis <desnacked at riseup.net>
Date:   Thu Jun 14 15:38:46 2018 +0300

    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.
---
 src/test/test_hs_common.c  |  3 ++-
 src/test/test_hs_service.c | 20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c
index 6296a709d..47a021312 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 684ac98f4..e328ca5bd 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());





More information about the tor-commits mailing list