mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Some unit tests now require that periodic events be initialized.
This commit is contained in:
+7
-2
@@ -1352,12 +1352,17 @@ initialize_periodic_events_cb(evutil_socket_t fd, short events, void *data)
|
||||
|
||||
/** Set up all the members of periodic_events[], and configure them all to be
|
||||
* launched from a callback. */
|
||||
static void
|
||||
STATIC void
|
||||
initialize_periodic_events(void)
|
||||
{
|
||||
tor_assert(periodic_events_initialized == 0);
|
||||
periodic_events_initialized = 1;
|
||||
|
||||
int i;
|
||||
for (i = 0; periodic_events[i].name; ++i) {
|
||||
periodic_event_setup(&periodic_events[i]);
|
||||
}
|
||||
|
||||
#define NAMED_CALLBACK(name) \
|
||||
STMT_BEGIN name ## _event = find_periodic_event( #name ); STMT_END
|
||||
|
||||
@@ -1372,7 +1377,7 @@ initialize_periodic_events(void)
|
||||
&one_second);
|
||||
}
|
||||
|
||||
static void
|
||||
STATIC void
|
||||
teardown_periodic_events(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -78,6 +78,8 @@ int tor_init(int argc, char **argv);
|
||||
#ifdef MAIN_PRIVATE
|
||||
STATIC void init_connection_lists(void);
|
||||
STATIC void close_closeable_connections(void);
|
||||
STATIC void initialize_periodic_events(void);
|
||||
STATIC void teardown_periodic_events(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+14
-4
@@ -78,12 +78,11 @@ periodic_event_reschedule(periodic_event_item_t *event)
|
||||
periodic_event_set_interval(event, 1);
|
||||
}
|
||||
|
||||
/** Handles initial dispatch for periodic events. It should happen 1 second
|
||||
* after the events are created to mimic behaviour before #3199's refactor */
|
||||
/** Initializes the libevent backend for a periodic event. */
|
||||
void
|
||||
periodic_event_launch(periodic_event_item_t *event)
|
||||
periodic_event_setup(periodic_event_item_t *event)
|
||||
{
|
||||
if (event->ev) { /** Already setup? This is a bug */
|
||||
if (event->ev) { /* Already setup? This is a bug */
|
||||
log_err(LD_BUG, "Initial dispatch should only be done once.");
|
||||
tor_assert(0);
|
||||
}
|
||||
@@ -93,6 +92,17 @@ periodic_event_launch(periodic_event_item_t *event)
|
||||
periodic_event_dispatch,
|
||||
event);
|
||||
tor_assert(event->ev);
|
||||
}
|
||||
|
||||
/** Handles initial dispatch for periodic events. It should happen 1 second
|
||||
* after the events are created to mimic behaviour before #3199's refactor */
|
||||
void
|
||||
periodic_event_launch(periodic_event_item_t *event)
|
||||
{
|
||||
if (! event->ev) { /* Not setup? This is a bug */
|
||||
log_err(LD_BUG, "periodic_event_launch without periodic_event_setup");
|
||||
tor_assert(0);
|
||||
}
|
||||
|
||||
// Initial dispatch
|
||||
periodic_event_dispatch(-1, EV_TIMEOUT, event);
|
||||
|
||||
@@ -29,6 +29,7 @@ typedef struct periodic_event_item_t {
|
||||
#define END_OF_PERIODIC_EVENTS { NULL, 0, NULL, NULL }
|
||||
|
||||
void periodic_event_launch(periodic_event_item_t *event);
|
||||
void periodic_event_setup(periodic_event_item_t *event);
|
||||
void periodic_event_destroy(periodic_event_item_t *event);
|
||||
void periodic_event_reschedule(periodic_event_item_t *event);
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#define ROUTER_PRIVATE
|
||||
#define CIRCUITSTATS_PRIVATE
|
||||
#define CIRCUITLIST_PRIVATE
|
||||
#define MAIN_PRIVATE
|
||||
#define STATEFILE_PRIVATE
|
||||
|
||||
/*
|
||||
@@ -50,6 +51,7 @@ double fabs(double x);
|
||||
#include "rendcache.h"
|
||||
#include "test.h"
|
||||
#include "torgzip.h"
|
||||
#include "main.h"
|
||||
#include "memarea.h"
|
||||
#include "onion.h"
|
||||
#include "onion_ntor.h"
|
||||
@@ -317,6 +319,8 @@ test_circuit_timeout(void *arg)
|
||||
int i, runs;
|
||||
double close_ms;
|
||||
(void)arg;
|
||||
initialize_periodic_events();
|
||||
|
||||
circuit_build_times_init(&initial);
|
||||
circuit_build_times_init(&estimate);
|
||||
circuit_build_times_init(&final);
|
||||
@@ -456,6 +460,7 @@ test_circuit_timeout(void *arg)
|
||||
circuit_build_times_free_timeouts(&estimate);
|
||||
circuit_build_times_free_timeouts(&final);
|
||||
or_state_free(state);
|
||||
teardown_periodic_events();
|
||||
}
|
||||
|
||||
/** Test encoding and parsing of rendezvous service descriptors. */
|
||||
|
||||
Reference in New Issue
Block a user