From ea931ffc94e1f8145c30c98da50cd5ae9dd5147a Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Tue, 7 May 2013 10:54:03 +0000 Subject: [PATCH] - add GNUNET_TESTING_peer_stop_async_cancel() --- src/include/gnunet_testing_lib.h | 13 +++++++++++++ src/testing/test_testing_peerstartup2.c | 8 ++++++-- src/testing/testing.c | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index bf5e9e522..6bb92e05d 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h @@ -349,6 +349,19 @@ GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, void *cb_cls); +/** + * Cancel a previous asynchronous peer stop request. + * GNUNET_TESTING_peer_stop_async() should have been called before on the given + * peer. It is an error to call this function if the peer stop callback was + * already called + * + * @param peer the peer on which GNUNET_TESTING_peer_stop_async() was called + * before. + */ +void +GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer); + + /** * Signature of the 'main' function for a (single-peer) testcase that * is run using 'GNUNET_TESTING_peer_run'. diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c index cd8141b40..959651041 100644 --- a/src/testing/test_testing_peerstartup2.c +++ b/src/testing/test_testing_peerstartup2.c @@ -148,10 +148,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_TESTING_peer_stop_async (test_ctx->peer, &peer_status_cb, test_ctx)); - } else - do_shutdown (test_ctx, tc); + do_shutdown2 (test_ctx, tc); } @@ -187,6 +186,11 @@ run (void *cls, char *const *args, const char *cfgfile, if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) goto end; test_ctx->state = PEER_STARTED; + FAIL_TEST (GNUNET_OK == + GNUNET_TESTING_peer_stop_async (test_ctx->peer, + &peer_status_cb, + test_ctx)); + GNUNET_TESTING_peer_stop_async_cancel (test_ctx->peer); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, test_ctx); return; diff --git a/src/testing/testing.c b/src/testing/testing.c index 1b2448ffc..f268c38d1 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -1538,6 +1538,24 @@ GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, } +/** + * Cancel a previous asynchronous peer stop request. + * GNUNET_TESTING_peer_stop_async() should have been called before on the given + * peer. It is an error to call this function if the peer stop callback was + * already called + * + * @param peer the peer on which GNUNET_TESTING_peer_stop_async() was called + * before. + */ +void +GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer) +{ + GNUNET_assert (NULL != peer->ah); + GNUNET_ARM_disconnect_and_free (peer->ah); + peer->ah = NULL; +} + + /** * Destroy the peer. Releases resources locked during peer configuration. * If the peer is still running, it will be stopped AND a warning will be -- 2.25.1