merge
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Wed, 25 Dec 2019 17:21:17 +0000 (02:21 +0900)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Wed, 25 Dec 2019 17:21:17 +0000 (02:21 +0900)
1  2 
src/transport/test_communicator_basic.c

index 4dba9d50ccb8b4f8fe2423f453952056e52176b4,e9b982897688d250e3ad9b3cb34397d722fbfdf4..db396ba661a3a62c31441af07d04f9dfa70a0f11
@@@ -64,6 -64,8 +64,8 @@@ static struct GNUNET_TIME_Absolute star
  
  static struct GNUNET_TIME_Absolute start_long;
  
+ static struct GNUNET_TIME_Absolute timeout;
  static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc;
  
  #define SHORT_MESSAGE_SIZE 128
@@@ -74,7 -76,7 +76,7 @@@
  
  #define FIXME_DEAD_BURST_RUNS 1
  
- #define TOTAL_ITERATIONS 10
+ #define TOTAL_ITERATIONS 20
  
  static unsigned int iterations_left = TOTAL_ITERATIONS;
  
@@@ -196,9 -198,18 +198,17 @@@ static voi
  latency_timeout (void *cls)
  {
    to_task = NULL;
+   if (GNUNET_TIME_absolute_get_remaining (timeout).rel_value_us > 0)
+   {
+     to_task = GNUNET_SCHEDULER_add_at (timeout,
+                                        &latency_timeout,
+                                        NULL);
+     return;
+   }
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
 -              "Latency too high. Test failed. (Phase: %d. Received: %lu\n",
 -              phase,
 -              num_received);
 +              "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n",
 +              phase, num_sent, num_received);
    ret = 2;
    GNUNET_SCHEDULER_shutdown ();
  }
@@@ -220,10 -231,7 +230,7 @@@ size_test (void *cls
    GNUNET_free (payload);
    ack += 5;
    num_sent++;
-   if (NULL == to_task)
-     to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                             &latency_timeout,
-                                             NULL);
+   timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
    if (ack < 64000)
      active_task = GNUNET_SCHEDULER_add_now (&size_test,
                                              NULL);
@@@ -242,10 -250,7 +249,7 @@@ long_test (void *cls
                                                          LONG_MESSAGE_SIZE);
    num_sent++;
    GNUNET_free (payload);
-   if (NULL == to_task)
-     to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                             &latency_timeout,
-                                             NULL);
+   timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
    if (num_sent == BURST_PACKETS)
      return;
    active_task = GNUNET_SCHEDULER_add_now (&long_test,
@@@ -265,10 -270,7 +269,7 @@@ short_test (void *cls
                                                          SHORT_MESSAGE_SIZE);
    num_sent++;
    GNUNET_free (payload);
-   if (NULL == to_task)
-     to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                             &latency_timeout,
-                                             NULL);
+   timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
    if (num_sent >= BURST_PACKETS)
      return;
    active_task = GNUNET_SCHEDULER_add_now (&short_test,
@@@ -300,6 -302,11 +301,11 @@@ add_queue_cb (void *cls
    start_short = GNUNET_TIME_absolute_get ();
    my_tc = tc_queue;
    phase = TP_BURST_SHORT;
+   timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
+   GNUNET_assert (NULL == to_task);
+   to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                           &latency_timeout,
+                                           NULL);
    GNUNET_assert (NULL == active_task);
    active_task = GNUNET_SCHEDULER_add_now (&short_test,
                                            NULL);
@@@ -347,6 -354,8 +353,8 @@@ incoming_message_cb (void *cls
                  "unexpected receiver...\n");
      return;
    }
+   /* Reset timeout */
+   timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
    switch (phase)
    {
    case TP_BURST_SHORT:
          num_sent = 0;
          avg_latency = 0;
          num_received = 0;
-         if (NULL != to_task)
-         {
-           GNUNET_SCHEDULER_cancel (to_task);
-           to_task = NULL;
-         }
          active_task = GNUNET_SCHEDULER_add_now (&long_test,
                                                  NULL);
        }
          num_received = 0;
          num_sent = 0;
          avg_latency = 0;
-         if (NULL != to_task)
-         {
-           GNUNET_SCHEDULER_cancel (to_task);
-           to_task = NULL;
-         }
          active_task = GNUNET_SCHEDULER_add_now (&size_test,
                                                  NULL);
        }
          num_received = 0;
          num_sent = 0;
          avg_latency = 0;
-         if (NULL != to_task)
-         {
-           GNUNET_SCHEDULER_cancel (to_task);
-           to_task = NULL;
-         }
          iterations_left--;
          if (0 != iterations_left)
          {
        break;
      }
    }
-   /* Reset timeout */
-   if (NULL != to_task)
-   {
-     GNUNET_SCHEDULER_cancel (to_task);
-     to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                             &latency_timeout,
-                                             NULL);
-   }
  }