summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-05-10 13:38:57 +0000
committerNathan S. Evans <evans@in.tum.de>2010-05-10 13:38:57 +0000
commit8219a880d84f4cbaf18e0d2443662e52c528d307 (patch)
treeb7b6998ab32f9c1eec40cc376c844cb6f7de7808 /src/testing
parentaf7d13f4f43d04c821b2bc70ec65a0900d65159b (diff)
change testing library to use timeout for peer and peergroup startup so testcase/user can decide how long to wait as opposed to arbitrary wait counts
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/test_testing.c6
-rw-r--r--src/testing/test_testing_connect.c8
-rw-r--r--src/testing/test_testing_group.c7
-rw-r--r--src/testing/test_testing_group_remote.c3
-rw-r--r--src/testing/test_testing_topology.c8
-rw-r--r--src/testing/testing.c39
-rw-r--r--src/testing/testing_group.c14
7 files changed, 47 insertions, 38 deletions
diff --git a/src/testing/test_testing.c b/src/testing/test_testing.c
index b33f3ee1b..9d8efe3f8 100644
--- a/src/testing/test_testing.c
+++ b/src/testing/test_testing.c
@@ -26,6 +26,8 @@
#define VERBOSE GNUNET_NO
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
static int ok;
static void
@@ -56,7 +58,7 @@ my_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Daemon `%s' started, will now stop it.\n", GNUNET_i2s (id));
#endif
- GNUNET_TESTING_daemon_stop (d, &end_cb, NULL, GNUNET_YES);
+ GNUNET_TESTING_daemon_stop (d, TIMEOUT, &end_cb, NULL, GNUNET_YES);
}
@@ -72,7 +74,7 @@ run (void *cls,
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemon.\n");
#endif
- d = GNUNET_TESTING_daemon_start (sched, cfg, NULL, NULL, NULL, &my_cb, NULL);
+ d = GNUNET_TESTING_daemon_start (sched, cfg, TIMEOUT, NULL, NULL, NULL, &my_cb, NULL);
GNUNET_assert (d != NULL);
}
diff --git a/src/testing/test_testing_connect.c b/src/testing/test_testing_connect.c
index a55207cec..3ce8acd71 100644
--- a/src/testing/test_testing_connect.c
+++ b/src/testing/test_testing_connect.c
@@ -69,14 +69,14 @@ static void
end1_cb (void *cls, const char *emsg)
{
GNUNET_assert (emsg == NULL);
- GNUNET_TESTING_daemon_stop (d2, &end2_cb, NULL, GNUNET_YES);
+ GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &end2_cb, NULL, GNUNET_YES);
d2 = NULL;
}
static void
finish_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
{
- GNUNET_TESTING_daemon_stop (d1, &end1_cb, NULL, GNUNET_YES);
+ GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &end1_cb, NULL, GNUNET_YES);
d1 = NULL;
}
@@ -121,7 +121,7 @@ my_cb1 (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Daemon `%s' started.\n", GNUNET_i2s (id));
#endif
- d2 = GNUNET_TESTING_daemon_start (sched, c2, NULL, NULL, NULL, &my_cb2, NULL);
+ d2 = GNUNET_TESTING_daemon_start (sched, c2, TIMEOUT, NULL, NULL, NULL, &my_cb2, NULL);
GNUNET_assert (d2 != NULL);
}
@@ -142,7 +142,7 @@ run (void *cls,
GNUNET_CONFIGURATION_parse (c1, "test_testing_connect_peer1.conf");
c2 = GNUNET_CONFIGURATION_create ();
GNUNET_CONFIGURATION_parse (c2, "test_testing_connect_peer2.conf");
- d1 = GNUNET_TESTING_daemon_start (sched, c1, NULL, NULL, NULL, &my_cb1, NULL);
+ d1 = GNUNET_TESTING_daemon_start (sched, c1, TIMEOUT, NULL, NULL, NULL, &my_cb1, NULL);
GNUNET_assert (d1 != NULL);
}
diff --git a/src/testing/test_testing_group.c b/src/testing/test_testing_group.c
index 966945003..2429c4525 100644
--- a/src/testing/test_testing_group.c
+++ b/src/testing/test_testing_group.c
@@ -33,7 +33,6 @@
*/
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
-
static int ok;
static int peers_left;
@@ -64,12 +63,13 @@ my_cb (void *cls,
{
sleep(2); /* Give other services a chance to initialize before killing */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully, ending test!\n");
- GNUNET_TESTING_daemons_stop (pg);
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
ok = 0;
}
else if (failed_peers == peers_left)
{
- GNUNET_TESTING_daemons_stop (pg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Too many peers failed, ending test!\n");
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
}
}
@@ -88,6 +88,7 @@ run (void *cls,
peers_left = NUM_PEERS;
pg = GNUNET_TESTING_daemons_start (sched, cfg,
peers_left,
+ TIMEOUT,
NULL, NULL,
&my_cb, NULL, NULL, NULL, NULL);
GNUNET_assert (pg != NULL);
diff --git a/src/testing/test_testing_group_remote.c b/src/testing/test_testing_group_remote.c
index c1bd2c8a6..6970fb634 100644
--- a/src/testing/test_testing_group_remote.c
+++ b/src/testing/test_testing_group_remote.c
@@ -59,7 +59,7 @@ my_cb (void *cls,
peers_left--;
if (peers_left == 0)
{
- GNUNET_TESTING_daemons_stop (pg);
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
ok = 0;
}
}
@@ -88,6 +88,7 @@ run (void *cls,
peers_left = num_peers;
pg = GNUNET_TESTING_daemons_start (sched, cfg,
peers_left,
+ TIMEOUT,
&my_cb, NULL, NULL, NULL, hostnames);
GNUNET_assert (pg != NULL);
}
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
index 30d83a72f..d00b52a0c 100644
--- a/src/testing/test_testing_topology.c
+++ b/src/testing/test_testing_topology.c
@@ -33,7 +33,7 @@
#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
/**
- * How long until we give up on connecting the peers?
+ * How long until we give up on starting the peers?
*/
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
@@ -177,7 +177,7 @@ finish_testing ()
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Calling daemons_stop\n");
#endif
- GNUNET_TESTING_daemons_stop (pg);
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"daemons_stop finished\n");
@@ -280,7 +280,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
if (pg != NULL)
{
- GNUNET_TESTING_daemons_stop (pg);
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
ok = 7331; /* Opposite of leet */
}
else
@@ -729,7 +729,7 @@ run (void *cls,
&end_badly, "didn't start all daemons in reasonable amount of time!!!");
pg = GNUNET_TESTING_daemons_start (sched, cfg,
- peers_left, &hostkey_callback, NULL, &peers_started_callback, NULL,
+ peers_left, TIMEOUT, &hostkey_callback, NULL, &peers_started_callback, NULL,
&topology_callback, NULL, NULL);
}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 65441c188..a73e48024 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -126,7 +126,7 @@ testing_init (void *cls,
{
d->server = NULL;
if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls, GNUNET_YES);
+ GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES);
else if (NULL != cb)
cb (d->cb_cls, NULL, d->cfg, d,
_("Failed to connect to core service\n"));
@@ -141,7 +141,7 @@ testing_init (void *cls,
d->server = server;
d->running = GNUNET_YES;
if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls, GNUNET_YES);
+ GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES);
else if (NULL != cb)
cb (d->cb_cls, my_identity, d->cfg, d, NULL);
#if DEBUG_TESTING
@@ -155,7 +155,7 @@ testing_init (void *cls,
if (d->th == NULL)
{
if (GNUNET_YES == d->dead)
- GNUNET_TESTING_daemon_stop (d, d->dead_cb, d->dead_cb_cls, GNUNET_YES);
+ GNUNET_TESTING_daemon_stop (d, GNUNET_TIME_absolute_get_remaining(d->max_timeout), d->dead_cb, d->dead_cb_cls, GNUNET_YES);
else if (NULL != d->cb)
d->cb (d->cb_cls, &d->id, d->cfg, d,
_("Failed to connect to transport service!\n"));
@@ -196,15 +196,14 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
/* confirm copying complete */
if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
{
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
{
cb = d->cb;
d->cb = NULL;
if (NULL != cb)
cb (d->cb_cls,
NULL,
- d->cfg, d, _("`scp' does not seem to terminate.\n"));
+ d->cfg, d, _("`scp' does not seem to terminate (timeout copying config).\n"));
return;
}
/* wait some more */
@@ -305,7 +304,6 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
"gnunet-peerinfo");
#endif
d->phase = SP_HOSTKEY_CREATE;
- d->wait_runs = 0;
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
GNUNET_CONSTANTS_EXEC_WAIT,
@@ -336,8 +334,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
{
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
{
cb = d->cb;
d->cb = NULL;
@@ -391,8 +388,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
/* Fall through */
case SP_HOSTKEY_CREATED:
/* wait for topology finished */
- d->wait_runs++;
- if ((GNUNET_YES == d->dead) || (d->wait_runs > MAX_EXEC_WAIT_RUNS))
+ if ((GNUNET_YES == d->dead) || (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0))
{
cb = d->cb;
d->cb = NULL;
@@ -475,7 +471,6 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
"gnunet-arm", "gnunet-service-core");
#endif
d->phase = SP_START_ARMING;
- d->wait_runs = 0;
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
GNUNET_CONSTANTS_EXEC_WAIT,
@@ -484,8 +479,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
case SP_START_ARMING:
if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
{
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
{
cb = d->cb;
d->cb = NULL;
@@ -530,8 +524,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
/* confirm copying complete */
if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
{
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0)
{
d->dead_cb (d->dead_cb_cls,
_("either `gnunet-arm' or `ssh' does not seem to terminate.\n"));
@@ -601,8 +594,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
/* confirm copying complete */
if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code))
{
- d->wait_runs++;
- if (d->wait_runs > MAX_EXEC_WAIT_RUNS)
+ if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).value == 0) /* FIXME: config update should take timeout parameter! */
{
cb = d->cb;
d->cb = NULL;
@@ -659,6 +651,7 @@ GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon)
*
* @param sched scheduler to use
* @param cfg configuration to use
+ * @param timeout how long to wait starting up peers
* @param hostname name of the machine where to run GNUnet
* (use NULL for localhost).
* @param hostkey_callback function to call once the hostkey has been
@@ -672,6 +665,7 @@ GNUNET_TESTING_daemon_continue_startup(struct GNUNET_TESTING_Daemon *daemon)
struct GNUNET_TESTING_Daemon *
GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TIME_Relative timeout,
const char *hostname,
GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
void *hostkey_cls,
@@ -701,6 +695,7 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
ret->hostkey_cls = hostkey_cls;
ret->cb = cb;
ret->cb_cls = cb_cls;
+ ret->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
GNUNET_CONFIGURATION_set_value_string (ret->cfg,
"PATHS",
@@ -868,7 +863,6 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
}
GNUNET_free_non_null(del_arg);
- d->wait_runs = 0;
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
GNUNET_CONSTANTS_EXEC_WAIT,
@@ -881,6 +875,7 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
* Stops a GNUnet daemon.
*
* @param d the daemon that should be stopped
+ * @param timeout how long to wait for process for shutdown to complete
* @param cb function called once the daemon was stopped
* @param cb_cls closure for cb
* @param delete_files GNUNET_YES to remove files, GNUNET_NO
@@ -889,6 +884,7 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d,
*/
void
GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
+ struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyCompletion cb, void *cb_cls,
int delete_files)
{
@@ -929,8 +925,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
_("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id));
#endif
- d->phase = SP_SHUTDOWN_START;
-
+ d->phase = SP_SHUTDOWN_START;
/* Check if this is a local or remote process */
if (NULL != d->hostname)
{
@@ -969,7 +964,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
}
GNUNET_free_non_null(del_arg);
- d->wait_runs = 0;
+ d->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
GNUNET_CONSTANTS_EXEC_WAIT,
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 57cea8007..eb83c9b78 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -240,6 +240,10 @@ struct GNUNET_TESTING_PeerGroup
*/
unsigned int total;
+ /**
+ * At what time should we fail the peer startup process?
+ */
+ struct GNUNET_TIME_Absolute max_timeout;
};
/**
@@ -2380,6 +2384,7 @@ GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg)
* @param sched scheduler to use
* @param cfg configuration template to use
* @param total number of daemons to start
+ * @param timeout total time allowed for peers to start
* @param hostkey_callback function to call on each peers hostkey generation
* if NULL, peers will be started by this call, if non-null,
* GNUNET_TESTING_daemons_continue_startup must be called after
@@ -2397,6 +2402,7 @@ struct GNUNET_TESTING_PeerGroup *
GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
const struct GNUNET_CONFIGURATION_Handle *cfg,
unsigned int total,
+ struct GNUNET_TIME_Relative timeout,
GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback,
void *hostkey_cls,
GNUNET_TESTING_NotifyDaemonRunning cb,
@@ -2432,6 +2438,7 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
pg->notify_connection = connect_callback;
pg->notify_connection_cls = connect_callback_cls;
pg->total = total;
+ pg->max_timeout = GNUNET_TIME_relative_to_absolute(timeout);
pg->peers = GNUNET_malloc (total * sizeof (struct PeerData));
if (NULL != hostnames)
{
@@ -2533,6 +2540,7 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
pg->peers[off].pg = pg;
pg->peers[off].daemon = GNUNET_TESTING_daemon_start (sched,
pcfg,
+ timeout,
hostname,
hostkey_callback,
hostkey_cls,
@@ -2628,9 +2636,11 @@ GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TEST
* Shutdown all peers started in the given group.
*
* @param pg handle to the peer group
+ * @param timeout how long to wait for shutdown
+ *
*/
void
-GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg)
+GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, struct GNUNET_TIME_Relative timeout)
{
unsigned int off;
@@ -2642,7 +2652,7 @@ GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg)
as well... */
if (NULL != pg->peers[off].daemon)
- GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, NULL, NULL, GNUNET_YES);
+ GNUNET_TESTING_daemon_stop (pg->peers[off].daemon, timeout, NULL, NULL, GNUNET_YES);
if (NULL != pg->peers[off].cfg)
GNUNET_CONFIGURATION_destroy (pg->peers[off].cfg);