check if peer has already been stopped before attempting to stop it again
authorSree Harsha Totakura <totakura@in.tum.de>
Fri, 31 Aug 2012 12:05:47 +0000 (12:05 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Fri, 31 Aug 2012 12:05:47 +0000 (12:05 +0000)
src/testbed/test_testbed_api_testbed_run.c
src/testbed/testbed_api_testbed.c

index a9a2a81926dfbf0ccefe163ddc5e903209ccffc1..2a7c77af00ad9ddd3ade107a2a5913bbf1e2ae87 100644 (file)
  */
 static struct GNUNET_TESTBED_Peer *peers[NUM_PEERS];
 
+/**
+ * Operation handle
+ */
+static struct GNUNET_TESTBED_Operation *op;
+
 /**
  * Abort task identifier
  */
@@ -95,8 +100,9 @@ static void
 master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   result = GNUNET_OK;
-  /* Artificial delay */
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL);
+  GNUNET_assert (NULL != peers[0]);
+  op = GNUNET_TESTBED_peer_stop (peers[0]);
+  GNUNET_assert (NULL != op);
 }
 
 
@@ -118,6 +124,12 @@ controller_event_cb (void *cls,
     GNUNET_assert (NULL != event->details.peer_start.peer);
     peers[peer_id++] = event->details.peer_start.peer;
     break;
+  case GNUNET_TESTBED_ET_PEER_STOP:
+    GNUNET_assert (NULL != op);
+    GNUNET_TESTBED_operation_done (op);
+    GNUNET_assert (peers[0] == event->details.peer_stop.peer);
+    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    break;
   default:
     GNUNET_assert (0);
   }
index fb9ed31b614f1ffb3618fdcc778eadc3ea0142a2..f9b67676e1839891701548459861b99494826abb 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "platform.h"
 #include "gnunet_testbed_service.h"
+#include "testbed_api_peers.h"
 
 /**
  * Generic loggins shorthand
@@ -500,13 +501,19 @@ shutdown_run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       rc->peer_count = 0;
       for (peer = 0; peer < rc->num_peers; peer++)
       {
+        if (PS_STARTED != rc->peers[peer]->state)
+        {
+          rc->peer_count++;
+          continue;
+        }
         dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
         dll_op->op = GNUNET_TESTBED_peer_stop (rc->peers[peer]);
         dll_op->cls = rc->peers[peer];
         GNUNET_CONTAINER_DLL_insert_tail (rc->dll_op_head, rc->dll_op_tail,
                                           dll_op);
       }
-      return;
+      if (rc->peer_count != rc->num_peers)
+        return;
     }
   }
   rc->state = RC_PEERS_DESTROYED;       /* No peers are present so we consider the