#define VERBOSE GNUNET_NO
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
static int ok;
static void
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);
}
#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);
}
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;
}
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);
}
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);
}
*/
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
-
static int ok;
static int peers_left;
{
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);
}
}
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);
peers_left--;
if (peers_left == 0)
{
- GNUNET_TESTING_daemons_stop (pg);
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
ok = 0;
}
}
peers_left = num_peers;
pg = GNUNET_TESTING_daemons_start (sched, cfg,
peers_left,
+ TIMEOUT,
&my_cb, NULL, NULL, NULL, hostnames);
GNUNET_assert (pg != NULL);
}
#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)
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");
if (pg != NULL)
{
- GNUNET_TESTING_daemons_stop (pg);
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
ok = 7331; /* Opposite of leet */
}
else
&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);
}
{
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"));
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
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"));
/* 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 */
"gnunet-peerinfo");
#endif
d->phase = SP_HOSTKEY_CREATE;
- d->wait_runs = 0;
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
GNUNET_CONSTANTS_EXEC_WAIT,
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;
/* 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;
"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,
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;
/* 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"));
/* 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;
*
* @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
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,
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",
}
GNUNET_free_non_null(del_arg);
- d->wait_runs = 0;
d->task
= GNUNET_SCHEDULER_add_delayed (d->sched,
GNUNET_CONSTANTS_EXEC_WAIT,
* 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
*/
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)
{
_("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)
{
}
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,
*/
unsigned int total;
+ /**
+ * At what time should we fail the peer startup process?
+ */
+ struct GNUNET_TIME_Absolute max_timeout;
};
/**
* @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
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,
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)
{
pg->peers[off].pg = pg;
pg->peers[off].daemon = GNUNET_TESTING_daemon_start (sched,
pcfg,
+ timeout,
hostname,
hostkey_callback,
hostkey_cls,
* 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;
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);