monitor test: don't block in main context if we already have messages
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 24 Feb 2015 15:25:34 +0000 (15:25 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 24 Feb 2015 17:00:26 +0000 (17:00 +0000)
Functions like become_monitor() sometimes iterate the main context,
which could leave us with unprocessed messages in f->monitored.
We need to drain that queue of unprocessed messages (setting flags
accordingly, which might meet the loop's exit condition or cause
a break) before we are willing to block in the main context again.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89222
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
test/monitor.c

index 32b7b5d..6983772 100644 (file)
@@ -541,7 +541,8 @@ test_become_monitor (Fixture *f,
 
   while (!got_unique || !got_a || !got_b || !got_c)
     {
-      test_main_context_iterate (f->ctx, TRUE);
+      if (g_queue_is_empty (&f->monitored))
+        test_main_context_iterate (f->ctx, TRUE);
 
       while ((m = g_queue_pop_head (&f->monitored)) != NULL)
         {
@@ -596,7 +597,8 @@ test_become_monitor (Fixture *f,
 
   while (!lost_unique || !lost_a || !lost_b || !lost_c)
     {
-      test_main_context_iterate (f->ctx, TRUE);
+      if (g_queue_is_empty (&f->monitored))
+        test_main_context_iterate (f->ctx, TRUE);
 
       while ((m = g_queue_pop_head (&f->monitored)) != NULL)
         {
@@ -651,7 +653,8 @@ test_become_monitor (Fixture *f,
 
   while (TRUE)
     {
-      test_main_context_iterate (f->ctx, TRUE);
+      if (g_queue_is_empty (&f->monitored))
+        test_main_context_iterate (f->ctx, TRUE);
 
       /* When we iterate all the connection's messages, we see ourselves
        * losing all our names, then we're disconnected. */