do not print two messages, one is enough
[oweals/gnunet.git] / src / set / test_set_union_result_full.c
index 2ddd65c7c78c13c08ef3c5a8dbfbf5287de6d242..f3f389dd01c5bf0244610bd1f87c9f2a1da1d9a5 100644 (file)
@@ -53,10 +53,14 @@ result_cb_set1 (void *cls, const struct GNUNET_SET_Element *element,
     case GNUNET_SET_STATUS_FAILURE:
       printf ("set 1: failure\n");
       ret = 1;
+      GNUNET_SCHEDULER_shutdown ();
       break;
     case GNUNET_SET_STATUS_DONE:
       printf ("set 1: done\n");
       GNUNET_SET_destroy (set1);
+      set1 = NULL;
+      if (NULL == set2)
+        GNUNET_SCHEDULER_shutdown ();
       break;
     default:
       GNUNET_assert (0);
@@ -76,10 +80,14 @@ result_cb_set2 (void *cls, const struct GNUNET_SET_Element *element,
     case GNUNET_SET_STATUS_FAILURE:
       printf ("set 2: failure\n");
       ret = 1;
+      GNUNET_SCHEDULER_shutdown ();
       break;
     case GNUNET_SET_STATUS_DONE:
       printf ("set 2: done\n");
       GNUNET_SET_destroy (set2);
+      set2 = NULL;
+      if (NULL == set1)
+        GNUNET_SCHEDULER_shutdown ();
       break;
     default:
       GNUNET_assert (0);
@@ -123,7 +131,7 @@ start (void *cls)
 
   listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION,
                                      &app_id, listen_cb, NULL);
-  oh = GNUNET_SET_prepare (&local_id, &app_id, &context_msg, 42,
+  oh = GNUNET_SET_prepare (&local_id, &app_id, &context_msg,
                            GNUNET_SET_RESULT_FULL,
                            result_cb_set1, NULL);
   GNUNET_SET_commit (oh, set1);
@@ -142,7 +150,7 @@ init_set2 (void *cls)
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n");
 
-  element.type = 0;
+  element.element_type = 0;
 
   element.data = "hello";
   element.size = strlen(element.data);
@@ -164,7 +172,7 @@ init_set1 (void)
 {
   struct GNUNET_SET_Element element;
 
-  element.type = 0;
+  element.element_type = 0;
 
   element.data = "hello";
   element.size = strlen(element.data);
@@ -201,7 +209,7 @@ test_iter ()
 
   iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION);
 
-  element.type = 0;
+  element.element_type = 0;
 
   element.data = "hello";
   element.size = strlen(element.data);
@@ -217,6 +225,23 @@ test_iter ()
 }
 
 
+/**
+ * Signature of the main function of a task.
+ *
+ * @param cls closure
+ * @param tc context information (why was this task triggered now)
+ */
+static void
+timeout_fail (void *cls,
+              const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    return;
+  GNUNET_SCHEDULER_shutdown ();
+  ret = 1;
+}
+
+
 /**
  * Signature of the 'main' function for a (single-peer) testcase that
  * is run using 'GNUNET_TESTING_peer_run'.
@@ -230,6 +255,10 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg,
      struct GNUNET_TESTING_Peer *peer)
 {
+
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
+                                &timeout_fail, NULL);
+
   config = cfg;
   GNUNET_CRYPTO_get_peer_identity (cfg, &local_id);
   printf ("my id (from CRYPTO): %s\n", GNUNET_i2s (&local_id));
@@ -253,7 +282,7 @@ main (int argc, char **argv)
                                     "test_set.conf",
                                     &run, NULL))
   {
-    return 0;
+    return 1;
   }
   return ret;
 }