aboutsummaryrefslogtreecommitdiff
path: root/src/lockmanager
diff options
context:
space:
mode:
authorharsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96>2012-06-20 14:24:45 +0000
committerharsha <harsha@140774ce-b5e7-0310-ab8b-a85725594a96>2012-06-20 14:24:45 +0000
commit0b10ada75ab89ed981981a60f63e3426bc612fea (patch)
tree8ebad6d7ad6e0ab4fb878a00df10a60e1d9a77dc /src/lockmanager
parentbcffc4050ee1190fead7e99229f12a1e529fcd81 (diff)
-fixed reply handling
git-svn-id: https://gnunet.org/svn/gnunet@22158 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/lockmanager')
-rw-r--r--src/lockmanager/Makefile.am1
-rw-r--r--src/lockmanager/lockmanager_api.c15
-rw-r--r--src/lockmanager/test_lockmanager_api.c107
3 files changed, 25 insertions, 98 deletions
diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am
index d08d02a85b..bf2ad5d38e 100644
--- a/src/lockmanager/Makefile.am
+++ b/src/lockmanager/Makefile.am
@@ -55,6 +55,7 @@ test_lockmanager_api_SOURCES = \
test_lockmanager_api.c
test_lockmanager_api_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
test_lockmanager_api_lockrelease_SOURCES = \
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c
index bfdb2c1824..77773ed36d 100644
--- a/src/lockmanager/lockmanager_api.c
+++ b/src/lockmanager/lockmanager_api.c
@@ -24,11 +24,6 @@
* @author Sree Harsha Totakura
*/
-/**
- * To be fixed:
- * Should the handle be freed when the connection to service is lost?
- * Should cancel_request have a call back (else simultaneous calls break)
- */
#include "platform.h"
#include "gnunet_common.h"
@@ -244,11 +239,11 @@ transmit_notify (void *cls, size_t size, void *buf)
}
if (GNUNET_NO == handle->in_replies)
{
+ handle->in_replies = GNUNET_YES;
GNUNET_CLIENT_receive (handle->conn,
&handle_replies,
handle,
GNUNET_TIME_UNIT_FOREVER_REL);
- handle->in_replies = GNUNET_YES;
}
return msg_size;
}
@@ -325,7 +320,7 @@ match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
if ( (match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain)) )
{
- match->matched_entry = lr;
+ match->matched_entry = lr;
return GNUNET_NO;
}
return GNUNET_YES;
@@ -478,11 +473,11 @@ handle_replies (void *cls,
handle);
return;
}
+ handle->in_replies = GNUNET_YES;
GNUNET_CLIENT_receive (handle->conn,
&handle_replies,
handle,
GNUNET_TIME_UNIT_FOREVER_REL);
- handle->in_replies = GNUNET_YES;
if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type))
{
GNUNET_break (0);
@@ -588,11 +583,11 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
}
h->hashmap = GNUNET_CONTAINER_multihashmap_create (15);
GNUNET_assert (NULL != h->hashmap);
+ h->in_replies = GNUNET_YES;
GNUNET_CLIENT_receive (h->conn,
&handle_replies,
h,
- GNUNET_TIME_UNIT_FOREVER_REL);
- h->in_replies = GNUNET_YES;
+ GNUNET_TIME_UNIT_FOREVER_REL);
LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
return h;
}
diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c
index f9f7aac0ce..4cc7454015 100644
--- a/src/lockmanager/test_lockmanager_api.c
+++ b/src/lockmanager/test_lockmanager_api.c
@@ -27,11 +27,11 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_lockmanager_service.h"
+#include "gnunet_testing_lib-new.h"
-#define VERBOSE GNUNET_YES
-
-#define VERBOSE_ARM 1
-
+/**
+ * Generic logging shortcut
+ */
#define LOG(kind,...) \
GNUNET_log (kind, __VA_ARGS__)
@@ -60,14 +60,9 @@ enum Test
static enum Test result;
/**
- * The process id of the GNUNET ARM process
- */
-static struct GNUNET_OS_Process *arm_pid = NULL;
-
-/**
* Configuration Handle
*/
-static struct GNUNET_CONFIGURATION_Handle *config;
+static const struct GNUNET_CONFIGURATION_Handle *config;
/**
* The handle to the lockmanager service
@@ -108,16 +103,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
if (NULL != request2)
GNUNET_LOCKMANAGER_cancel_request (request2);
GNUNET_LOCKMANAGER_disconnect (handle);
- if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Kill gnunet-service-arm manually\n");
- }
- GNUNET_OS_process_wait (arm_pid);
- GNUNET_OS_process_destroy (arm_pid);
-
- if (NULL != config)
- GNUNET_CONFIGURATION_destroy (config);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -186,14 +172,15 @@ status_cb (void *cls,
/**
- * Testing function
- *
- * @param cls NULL
- * @param tc the task context
+ * Main point of test execution
*/
static void
-test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_TESTING_Peer *peer)
+{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
+ config = cfg;
handle = GNUNET_LOCKMANAGER_connect (config);
GNUNET_assert (NULL != handle);
result = LOCK1_ACQUIRE;
@@ -202,78 +189,22 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99,
&status_cb,
NULL);
- abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10),
+ abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (30),
&do_abort,
NULL);
}
/**
- * Main point of test execution
- */
-static void
-run (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
- config = GNUNET_CONFIGURATION_dup (cfg);
- arm_pid =
- GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
-#if VERBOSE_ARM
- "-L", "DEBUG",
-#endif
- "-c", "test_lockmanager_api.conf", NULL);
-
- GNUNET_assert (NULL != arm_pid);
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (3),
- &test,
- NULL);
-}
-
-
-/**
* Main function
*/
int main (int argc, char **argv)
{
- int ret;
-
- char *const argv2[] = { "test_lockmanager_api",
- "-c", "test_lockmanager_api.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
-
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
-
- GNUNET_log_setup ("test_lockmanager_api",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
- ret =
- GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
- "test_lockmanager_api", "nohelp", options, &run, NULL);
-
- if (GNUNET_OK != ret)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
- ret);
- return 1;
- }
- if (TEST_FAIL == result)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
+ if (0 != GNUNET_TESTING_service_run_restartable ("test_lockmanager_api",
+ "arm",
+ "test_lockmanager_api.conf",
+ &run, NULL))
return 1;
- }
- LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n");
- return 0;
+ return (TEST_FAIL == result) ? 1 : 0;
}