Browse Source

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.
George Kadianakis 5 years ago
parent
commit
2e8d4139a7
2 changed files with 20 additions and 3 deletions
  1. 2 1
      src/test/test_hs_common.c
  2. 18 2
      src/test/test_hs_service.c

+ 2 - 1
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 ===

+ 18 - 2
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());