[glib] Fix race condition in gapplication/basic test



commit edf94ba2631b8c4d32e798eaec69ceb89d6b32a8
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date:   Thu Nov 29 17:48:35 2012 +0100

    Fix race condition in gapplication/basic test
    
    The three processes this test creates need to be executed
    in order, and g_usleep was used to guarantee that.
    However, under heavy load, that is not enough. Instead,
    wait until the children start by making sure they have
    written to stdout before proceeding any further.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=664627

 gio/tests/gapplication.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/gio/tests/gapplication.c b/gio/tests/gapplication.c
index 6e247a8..8769693 100644
--- a/gio/tests/gapplication.c
+++ b/gio/tests/gapplication.c
@@ -61,6 +61,7 @@ spawn (const gchar *expected_stdout,
   gchar **args;
   va_list ap;
   GPid pid;
+  GPollFD fd;
 
   va_start (ap, first_arg);
   array = g_ptr_array_new ();
@@ -83,6 +84,14 @@ spawn (const gchar *expected_stdout,
 
   g_child_watch_add (pid, child_quit, data);
   outstanding_watches++;
+
+  /* we block until the children write to stdout to make sure
+   * they have started, as they need to be executed in order;
+   * see https://bugzilla.gnome.org/show_bug.cgi?id=664627
+   */
+  fd.fd = data->stdout_pipe;
+  fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
+  g_poll (&fd, 1, -1);
 }
 
 static void
@@ -102,16 +111,10 @@ basic (void)
          "exit status: 0\n",
          "./app", NULL);
 
-  /* make sure it becomes the master */
-  g_usleep (100000);
-
   /* send it some files */
   spawn ("exit status: 0\n",
          "./app", "/a", "/b", NULL);
 
-  /* make sure the commandline arrives after the files */
-  g_usleep (100000);
-
   spawn ("40 + 2 = 42\n"
          "exit status: 42\n",
          "./cmd", "40 +", "2", NULL);



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