Commit 4c19eed3 authored by David Goulet's avatar David Goulet 🆘
Browse files

tests: Fix unit tests after adding new HS metrics module


Signed-off-by: David Goulet's avatarDavid Goulet <dgoulet@torproject.org>
parent f2e42045
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include "feature/hs/hs_ob.h" #include "feature/hs/hs_ob.h"
#include "feature/hs/hs_cell.h" #include "feature/hs/hs_cell.h"
#include "feature/hs/hs_intropoint.h" #include "feature/hs/hs_intropoint.h"
#include "feature/hs/hs_metrics.h"
#include "feature/hs/hs_service.h" #include "feature/hs/hs_service.h"
#include "feature/nodelist/networkstatus.h" #include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h" #include "feature/nodelist/nodelist.h"
...@@ -664,6 +665,7 @@ test_access_service(void *arg) ...@@ -664,6 +665,7 @@ test_access_service(void *arg)
tt_mem_op(query, OP_EQ, s, sizeof(hs_service_t)); tt_mem_op(query, OP_EQ, s, sizeof(hs_service_t));
/* Remove service, check if it actually works and then put it back. */ /* Remove service, check if it actually works and then put it back. */
remove_service(global_map, s); remove_service(global_map, s);
hs_metrics_service_free(s);
tt_int_op(get_hs_service_map_size(), OP_EQ, 0); tt_int_op(get_hs_service_map_size(), OP_EQ, 0);
query = find_service(global_map, &s->keys.identity_pk); query = find_service(global_map, &s->keys.identity_pk);
tt_ptr_op(query, OP_EQ, NULL); tt_ptr_op(query, OP_EQ, NULL);
...@@ -673,6 +675,7 @@ test_access_service(void *arg) ...@@ -673,6 +675,7 @@ test_access_service(void *arg)
tt_int_op(ret, OP_EQ, 0); tt_int_op(ret, OP_EQ, 0);
tt_int_op(get_hs_service_map_size(), OP_EQ, 1); tt_int_op(get_hs_service_map_size(), OP_EQ, 1);
/* Twice should fail. */ /* Twice should fail. */
hs_metrics_service_free(s); /* Avoid BUG() on metrics init. */
ret = register_service(global_map, s); ret = register_service(global_map, s);
tt_int_op(ret, OP_EQ, -1); tt_int_op(ret, OP_EQ, -1);
/* Remove service from map so we don't double free on cleanup. */ /* Remove service from map so we don't double free on cleanup. */
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "core/or/or.h" #include "core/or/or.h"
#include "app/config/config.h" #include "app/config/config.h"
#include "feature/hibernate/hibernate.h" #include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_metrics.h"
#include "feature/hs/hs_service.h" #include "feature/hs/hs_service.h"
#include "core/mainloop/mainloop.h" #include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h" #include "core/mainloop/netstatus.h"
...@@ -187,6 +188,7 @@ test_pe_launch(void *arg) ...@@ -187,6 +188,7 @@ test_pe_launch(void *arg)
done: done:
if (to_remove) { if (to_remove) {
hs_metrics_service_free(&service);
remove_service(get_hs_service_map(), to_remove); remove_service(get_hs_service_map(), to_remove);
} }
hs_free_all(); hs_free_all();
...@@ -279,6 +281,7 @@ test_pe_get_roles(void *arg) ...@@ -279,6 +281,7 @@ test_pe_get_roles(void *arg)
roles = get_my_roles(options); roles = get_my_roles(options);
/* Remove it now so the hs_free_all() doesn't try to free stack memory. */ /* Remove it now so the hs_free_all() doesn't try to free stack memory. */
remove_service(get_hs_service_map(), &service); remove_service(get_hs_service_map(), &service);
hs_metrics_service_free(&service);
tt_int_op(roles, OP_EQ, 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_HS_SERVICE | PERIODIC_EVENT_ROLE_DIRSERVER | PERIODIC_EVENT_ROLE_HS_SERVICE | PERIODIC_EVENT_ROLE_DIRSERVER |
...@@ -332,6 +335,7 @@ test_pe_hs_service(void *arg) ...@@ -332,6 +335,7 @@ test_pe_hs_service(void *arg)
/* Remove the service from the global map, it should trigger a rescan and /* Remove the service from the global map, it should trigger a rescan and
* disable the HS service events. */ * disable the HS service events. */
remove_service(get_hs_service_map(), &service); remove_service(get_hs_service_map(), &service);
hs_metrics_service_free(&service);
for (int i = 0; mainloop_periodic_events[i].name; ++i) { for (int i = 0; mainloop_periodic_events[i].name; ++i) {
periodic_event_item_t *item = &mainloop_periodic_events[i]; periodic_event_item_t *item = &mainloop_periodic_events[i];
if (item->roles & PERIODIC_EVENT_ROLE_HS_SERVICE) { if (item->roles & PERIODIC_EVENT_ROLE_HS_SERVICE) {
...@@ -341,6 +345,7 @@ test_pe_hs_service(void *arg) ...@@ -341,6 +345,7 @@ test_pe_hs_service(void *arg)
done: done:
if (to_remove) { if (to_remove) {
hs_metrics_service_free(&service);
remove_service(get_hs_service_map(), to_remove); remove_service(get_hs_service_map(), to_remove);
} }
hs_free_all(); hs_free_all();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment