diff options
Diffstat (limited to 'src/test/test_hs_common.c')
-rw-r--r-- | src/test/test_hs_common.c | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c index e41d68d42e..a5c499112e 100644 --- a/src/test/test_hs_common.c +++ b/src/test/test_hs_common.c @@ -200,9 +200,9 @@ test_desc_overlap_period(void *arg) time_t now = time(NULL); networkstatus_t *dummy_consensus = NULL; - /* First try with a consensus inside the overlap period */ + /* First try with a consensus just inside the overlap period */ dummy_consensus = tor_malloc_zero(sizeof(networkstatus_t)); - retval = parse_rfc1123_time("Wed, 13 Apr 2016 10:00:00 UTC", + retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:00:00 UTC", &dummy_consensus->valid_after); tt_int_op(retval, ==, 0); @@ -211,7 +211,7 @@ test_desc_overlap_period(void *arg) /* Now increase the valid_after so that it goes to 11:00:00 UTC. Overlap period is still active. */ - dummy_consensus->valid_after += 3600; + dummy_consensus->valid_after += 3600*11; retval = hs_overlap_mode_is_active(dummy_consensus, now); tt_int_op(retval, ==, 1); @@ -238,6 +238,70 @@ test_desc_overlap_period(void *arg) tor_free(dummy_consensus); } +/* Test the overlap period functions on a testnet with altered voting + * schedule */ +static void +test_desc_overlap_period_testnet(void *arg) +{ + int retval; + time_t now = approx_time(); + networkstatus_t *dummy_consensus = NULL; + or_options_t *options = get_options_mutable(); + + (void) arg; + + /* Set the testnet option and a 10-second voting interval */ + options->TestingTorNetwork = 1; + options->V3AuthVotingInterval = 10; + options->TestingV3AuthInitialVotingInterval = 10; + + dummy_consensus = tor_malloc_zero(sizeof(networkstatus_t)); + + /* A 10-second voting interval means that the lengths of an SRV run and of a + * time period are both 10*24 seconds (4 minutes). The SRV gets published at + * 00:00:00 and the TP starts at 00:02:00 (rotation offset: 2 mins). Those + * two minutes between SRV publish and TP start is the overlap period + * window. Let's test it: */ + retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:00:00 UTC", + &dummy_consensus->valid_after); + tt_int_op(retval, ==, 0); + retval = hs_overlap_mode_is_active(dummy_consensus, now); + tt_int_op(retval, ==, 1); + + retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:01:59 UTC", + &dummy_consensus->valid_after); + tt_int_op(retval, ==, 0); + retval = hs_overlap_mode_is_active(dummy_consensus, now); + tt_int_op(retval, ==, 1); + + retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:02:00 UTC", + &dummy_consensus->valid_after); + tt_int_op(retval, ==, 0); + retval = hs_overlap_mode_is_active(dummy_consensus, now); + tt_int_op(retval, ==, 0); + + retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:04:00 UTC", + &dummy_consensus->valid_after); + tt_int_op(retval, ==, 0); + retval = hs_overlap_mode_is_active(dummy_consensus, now); + tt_int_op(retval, ==, 1); + + retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:05:59 UTC", + &dummy_consensus->valid_after); + tt_int_op(retval, ==, 0); + retval = hs_overlap_mode_is_active(dummy_consensus, now); + tt_int_op(retval, ==, 1); + + retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:06:00 UTC", + &dummy_consensus->valid_after); + tt_int_op(retval, ==, 0); + retval = hs_overlap_mode_is_active(dummy_consensus, now); + tt_int_op(retval, ==, 0); + + done: + tor_free(dummy_consensus); +} + struct testcase_t hs_common_tests[] = { { "build_address", test_build_address, TT_FORK, NULL, NULL }, @@ -249,6 +313,8 @@ struct testcase_t hs_common_tests[] = { TT_FORK, NULL, NULL }, { "desc_overlap_period", test_desc_overlap_period, TT_FORK, NULL, NULL }, + { "desc_overlap_period_testnet", test_desc_overlap_period_testnet, TT_FORK, + NULL, NULL }, END_OF_TESTCASES }; |