commit d1a0534649be02e37668073279664f513f4dc7d7 Author: Nick Mathewson nickm@torproject.org Date: Mon Apr 30 10:36:00 2018 -0400
Make unit tests pass with new dirserver role. --- src/test/test_periodic_event.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/src/test/test_periodic_event.c b/src/test/test_periodic_event.c index 74e799360..34689b64f 100644 --- a/src/test/test_periodic_event.c +++ b/src/test/test_periodic_event.c @@ -118,6 +118,10 @@ test_pe_launch(void *arg) options->ORPort_set = 1; periodic_events_on_new_options(options);
+ unsigned roles = get_my_roles(options); + tt_uint_op(roles, OP_EQ, + PERIODIC_EVENT_ROLE_RELAY|PERIODIC_EVENT_ROLE_DIRSERVER); + for (int i = 0; periodic_events[i].name; ++i) { periodic_event_item_t *item = &periodic_events[i]; /* Only Client role should be disabled. */ @@ -130,8 +134,8 @@ test_pe_launch(void *arg) tt_int_op(periodic_event_is_enabled(item), OP_EQ, 1); tt_u64_op(item->last_action_time, OP_NE, 0); } - /* Non Relay role should be disabled! */ - if (!(item->roles & PERIODIC_EVENT_ROLE_RELAY)) { + /* Non Relay role should be disabled, except for Dirserver. */ + if (!(item->roles & roles)) { tt_int_op(periodic_event_is_enabled(item), OP_EQ, 0); } } @@ -196,19 +200,21 @@ test_pe_get_roles(void *arg) options->ORPort_set = 1; roles = get_my_roles(options); tt_int_op(roles, OP_EQ, - (PERIODIC_EVENT_ROLE_CLIENT | PERIODIC_EVENT_ROLE_RELAY)); + (PERIODIC_EVENT_ROLE_CLIENT | PERIODIC_EVENT_ROLE_RELAY | + PERIODIC_EVENT_ROLE_DIRSERVER));
/* Now add a Bridge. */ options->BridgeRelay = 1; roles = get_my_roles(options); tt_int_op(roles, OP_EQ, (PERIODIC_EVENT_ROLE_CLIENT | PERIODIC_EVENT_ROLE_RELAY | - PERIODIC_EVENT_ROLE_BRIDGE)); + PERIODIC_EVENT_ROLE_BRIDGE | PERIODIC_EVENT_ROLE_DIRSERVER)); tt_assert(roles & PERIODIC_EVENT_ROLE_ROUTER); /* Unset client so we can solely test Router role. */ options->SocksPort_set = 0; roles = get_my_roles(options); - tt_int_op(roles, OP_EQ, PERIODIC_EVENT_ROLE_ROUTER); + tt_int_op(roles, OP_EQ, + PERIODIC_EVENT_ROLE_ROUTER | PERIODIC_EVENT_ROLE_DIRSERVER);
/* Reset options so we can test authorities. */ options->SocksPort_set = 0; @@ -218,24 +224,28 @@ test_pe_get_roles(void *arg) tt_int_op(roles, OP_EQ, 0);
/* Now upgrade to Dirauth. */ + options->DirPort_set = 1; options->AuthoritativeDir = 1; options->V3AuthoritativeDir = 1; roles = get_my_roles(options); - tt_int_op(roles, OP_EQ, PERIODIC_EVENT_ROLE_DIRAUTH); + tt_int_op(roles, OP_EQ, + PERIODIC_EVENT_ROLE_DIRAUTH|PERIODIC_EVENT_ROLE_DIRSERVER); tt_assert(roles & PERIODIC_EVENT_ROLE_AUTHORITIES);
/* Now Bridge Authority. */ options->V3AuthoritativeDir = 0; options->BridgeAuthoritativeDir = 1; roles = get_my_roles(options); - tt_int_op(roles, OP_EQ, PERIODIC_EVENT_ROLE_BRIDGEAUTH); + tt_int_op(roles, OP_EQ, + PERIODIC_EVENT_ROLE_BRIDGEAUTH|PERIODIC_EVENT_ROLE_DIRSERVER); tt_assert(roles & PERIODIC_EVENT_ROLE_AUTHORITIES);
/* Move that bridge auth to become a relay. */ options->ORPort_set = 1; roles = get_my_roles(options); tt_int_op(roles, OP_EQ, - (PERIODIC_EVENT_ROLE_BRIDGEAUTH | PERIODIC_EVENT_ROLE_RELAY)); + (PERIODIC_EVENT_ROLE_BRIDGEAUTH | PERIODIC_EVENT_ROLE_RELAY + | PERIODIC_EVENT_ROLE_DIRSERVER)); tt_assert(roles & PERIODIC_EVENT_ROLE_AUTHORITIES);
/* And now an Hidden service. */ @@ -246,7 +256,7 @@ test_pe_get_roles(void *arg) remove_service(get_hs_service_map(), &service); tt_int_op(roles, OP_EQ, (PERIODIC_EVENT_ROLE_BRIDGEAUTH | PERIODIC_EVENT_ROLE_RELAY | - PERIODIC_EVENT_ROLE_HS_SERVICE)); + PERIODIC_EVENT_ROLE_HS_SERVICE | PERIODIC_EVENT_ROLE_DIRSERVER)); tt_assert(roles & PERIODIC_EVENT_ROLE_AUTHORITIES);
done: