From: Nathan S. Evans Date: Wed, 5 Jan 2011 16:29:04 +0000 (+0000) Subject: make testcase end more gracefully X-Git-Tag: initial-import-from-subversion-38251~19367 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=40199d8739a6aa36b279b31aa7532b66a5c8b735;p=oweals%2Fgnunet.git make testcase end more gracefully --- diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c index bf2697eec..e8121e327 100644 --- a/src/core/test_core_api_send_to_self.c +++ b/src/core/test_core_api_send_to_self.c @@ -35,10 +35,17 @@ */ static int ret; +/** + * Handle to the cleanup task. + */ +GNUNET_SCHEDULER_TaskIdentifier die_task; + +static struct GNUNET_PeerIdentity myself; + /** * The handle to core */ -static struct GNUNET_CORE_Handle *core_handle; +struct GNUNET_CORE_Handle *core; /** * Function scheduled as very last function, cleans up after us @@ -46,23 +53,26 @@ static struct GNUNET_CORE_Handle *core_handle; static void cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tskctx) { - GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); + die_task = GNUNET_SCHEDULER_NO_TASK; - if (core_handle != NULL) + if (core != NULL) { - GNUNET_CORE_disconnect (core_handle); - core_handle = NULL; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting core.\n"); + GNUNET_CORE_disconnect (core); + core = NULL; } -} - -static struct GNUNET_PeerIdentity myself; -struct GNUNET_CORE_Handle *core; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n"); +} static int receive(void* cls, const struct GNUNET_PeerIdentity* other, const struct GNUNET_MessageHeader* message, const struct GNUNET_TRANSPORT_ATS_Information* atsi) { + if (die_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel(die_task); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n", GNUNET_i2s(other)); + GNUNET_SCHEDULER_add_now(&cleanup, NULL); + ret = 0; return GNUNET_OK; } @@ -139,7 +149,7 @@ run (void *cls, init, connect_cb, NULL, NULL, NULL, 0, NULL, 0, handlers); - GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); + die_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), &cleanup, cls); } /**