gdbus-connection: Work around race in connection tests
[platform/upstream/glib.git] / gio / tests / gdbus-threading.c
index b46af0b..1c1f1df 100644 (file)
@@ -297,7 +297,8 @@ test_sleep_in_thread_func (gpointer _data)
                              (GAsyncReadyCallback) sleep_cb,
                              data);
           g_main_loop_run (data->thread_loop);
-          g_print ("A");
+          if (!g_test_quiet ())
+            g_print ("A");
           //g_debug ("done invoking async (%p)", g_thread_self ());
         }
       else
@@ -314,7 +315,8 @@ test_sleep_in_thread_func (gpointer _data)
                                            -1,
                                            NULL,
                                            &error);
-          g_print ("S");
+          if (!g_test_quiet ())
+            g_print ("S");
           //g_debug ("done invoking sync (%p)", g_thread_self ());
           g_assert_no_error (error);
           g_assert (result != NULL);
@@ -406,9 +408,10 @@ test_method_calls_on_proxy (GDBusProxy *proxy)
 
       /* elapsed_msec should be 4000 msec +/- change for overhead/inaccuracy */
       g_assert_cmpint (elapsed_msec, >=, 3950);
-      g_assert_cmpint (elapsed_msec,  <, 6000);
+      g_assert_cmpint (elapsed_msec,  <, 8000);
 
-      g_print (" ");
+      if (!g_test_quiet ())
+        g_print (" ");
     }
 }
 
@@ -444,6 +447,9 @@ test_method_calls_in_thread (void)
 
   g_object_unref (proxy);
   g_object_unref (connection);
+
+  if (!g_test_quiet ())
+    g_print ("\n");
 }
 
 #define SLEEP_MIN_USEC 1
@@ -581,25 +587,16 @@ main (int   argc,
 {
   GError *error;
   gint ret;
+  gchar *path;
 
-  g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
-  /* all the tests use a session bus with a well-known address that we can bring up and down
-   * using session_bus_up() and session_bus_down().
-   */
-  g_unsetenv ("DISPLAY");
-  g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
-
   session_bus_up ();
 
-  /* TODO: wait a bit for the bus to come up.. ideally session_bus_up() won't return
-   * until one can connect to the bus but that's not how things work right now
-   */
-  usleep (500 * 1000);
-
   /* this is safe; testserver will exit once the bus goes away */
-  g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
+  path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL);
+  g_assert (g_spawn_command_line_async (path, NULL));
+  g_free (path);
 
   /* wait for the service to come up */
   usleep (500 * 1000);