[glib/wip/tingping/localhost-is-local: 791/792] tests: Don't block mainloop for delays in gnetworkaddress tests



commit 5637e7f46e324a84145077bc941bf3d57172dbfd
Author: Patrick Griffis <pgriffis igalia com>
Date:   Tue Feb 5 08:50:09 2019 -0500

    tests: Don't block mainloop for delays in gnetworkaddress tests

 gio/tests/network-address.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/gio/tests/network-address.c b/gio/tests/network-address.c
index bda76050a..7883a8884 100644
--- a/gio/tests/network-address.c
+++ b/gio/tests/network-address.c
@@ -421,10 +421,22 @@ test_loopback_sync (void)
 typedef struct {
   GList/*<owned GSocketAddress> */ *addrs;  /* owned */
   GMainLoop *loop;  /* owned */
+  GSocketAddressEnumerator *enumerator; /* unowned */
   guint delay_ms;
   gint expected_error_code;
 } AsyncData;
 
+static void got_addr (GObject *source_object, GAsyncResult *result, gpointer user_data);
+
+static int
+on_delayed_get_addr (gpointer user_data)
+{
+  AsyncData *data = user_data;
+  g_socket_address_enumerator_next_async (data->enumerator, NULL,
+                                          got_addr, user_data);
+  return G_SOURCE_REMOVE;
+}
+
 static void
 got_addr (GObject      *source_object,
           GAsyncResult *result,
@@ -459,11 +471,14 @@ got_addr (GObject      *source_object,
       g_assert (G_IS_INET_SOCKET_ADDRESS (a));
       data->addrs = g_list_prepend (data->addrs, a);
 
-      if (data->delay_ms)
-        g_usleep (data->delay_ms * 1000);
-
-      g_socket_address_enumerator_next_async (enumerator, NULL,
-                                              got_addr, user_data);
+      if (!data->delay_ms)
+        g_socket_address_enumerator_next_async (enumerator, NULL,
+                                                got_addr, user_data);
+      else
+        {
+          data->enumerator = enumerator;
+          g_timeout_add (data->delay_ms, on_delayed_get_addr, data);
+        }
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]