-fixed reply handling
authorSree Harsha Totakura <totakura@in.tum.de>
Wed, 20 Jun 2012 14:24:45 +0000 (14:24 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Wed, 20 Jun 2012 14:24:45 +0000 (14:24 +0000)
src/lockmanager/Makefile.am
src/lockmanager/lockmanager_api.c
src/lockmanager/test_lockmanager_api.c

index d08d02a85b7ce51752430b39181f482aa1260873..bf2ad5d38e3a51f599594b2aa7a80caad8b1a4ba 100644 (file)
@@ -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 = \
index bfdb2c182418f7fcea0b5feab9e462571edea98b..77773ed36d68fe4aabd30ba8c76d2a66c90b6f4a 100644 (file)
  * @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;
 }
index f9f7aac0ce0a0e7da15a9f570a6a8d0c297c0122..4cc7454015372fdeb37ca2cdc5deea912a2a4b3b 100644 (file)
 #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__)
 
@@ -59,15 +59,10 @@ 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;
 }