rps tests: proper shutdown
authorJulius Bünger <buenger@mytum.de>
Sun, 7 Jan 2018 21:07:31 +0000 (22:07 +0100)
committerJulius Bünger <buenger@mytum.de>
Sun, 7 Jan 2018 21:33:08 +0000 (22:33 +0100)
src/rps/test_rps.c

index 992b4dc5458e3d34a8e0a98ee2d278cca7b6e03b..0268ff4389dd8893adb9927c521fc9ba0155da71 100644 (file)
@@ -261,6 +261,11 @@ static unsigned int num_peers_online;
  */
 static int ok;
 
+/**
+ * Identifier for the churn task that runs periodically
+ */
+static struct GNUNET_SCHEDULER_Task *shutdown_task;
+
 /**
  * Identifier for the churn task that runs periodically
  */
@@ -782,7 +787,10 @@ default_reply_handle (void *cls,
 
   if (0 == evaluate ())
   {
-    GNUNET_SCHEDULER_shutdown ();
+    GNUNET_assert (NULL != shutdown_task);
+    GNUNET_SCHEDULER_cancel (shutdown_task);
+    shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
+    GNUNET_assert (NULL!= shutdown_task);
   }
 }
 
@@ -1289,6 +1297,8 @@ churn (void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Churn function executing\n");
 
+  churn_task = NULL; /* Should be invalid by now */
+
   /* Compute the probability for an online peer to go offline
    * this round */
   portion_online = num_peers_online * 1.0 / num_peers;
@@ -1560,7 +1570,7 @@ run (void *cls,
 
   if (NULL != churn_task)
     GNUNET_SCHEDULER_cancel (churn_task);
-  GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
+  shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
 }