[libsoup] cache-test: fix race condition



commit 164e49a27eeeedca800f466b0b14a4e61a162007
Author: Dan Winship <danw gnome org>
Date:   Fri Aug 23 13:34:37 2013 -0400

    cache-test: fix race condition
    
    The refcounting test had a race condition. Fix it by just waiting for
    the stream to be destroyed, rather than asserting it already has been.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=698305

 tests/cache-test.c |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)
---
diff --git a/tests/cache-test.c b/tests/cache-test.c
index 34389f8..a8d01eb 100644
--- a/tests/cache-test.c
+++ b/tests/cache-test.c
@@ -571,6 +571,19 @@ do_cancel_test (SoupURI *base_uri)
        g_free (body2);
 }
 
+static gboolean
+unref_stream (gpointer stream)
+{
+       g_object_unref (stream);
+       return FALSE;
+}
+
+static void
+base_stream_unreffed (gpointer loop, GObject *ex_base_stream)
+{
+       g_main_loop_quit (loop);
+}
+
 static void
 do_refcounting_test (SoupURI *base_uri)
 {
@@ -582,6 +595,7 @@ do_refcounting_test (SoupURI *base_uri)
        SoupURI *uri;
        GError *error = NULL;
        guint flags;
+       GMainLoop *loop;
 
        debug_printf (1, "Cache refcounting tests\n");
 
@@ -609,19 +623,16 @@ do_refcounting_test (SoupURI *base_uri)
                g_object_unref (req);
                return;
        }
+       g_object_unref (req);
 
        base_stream = g_filter_input_stream_get_base_stream (G_FILTER_INPUT_STREAM (stream));
-       g_object_add_weak_pointer (G_OBJECT (base_stream), (gpointer *)&base_stream);
-
-       g_clear_object (&req);
-       g_object_unref (stream);
 
        debug_printf (1, " Checking that the base stream is properly unref'ed\n");
-       if (base_stream) {
-               errors++;
-               debug_printf (1, "leaked GInputStream!\n");
-               g_object_remove_weak_pointer (G_OBJECT (base_stream), (gpointer *)&base_stream);
-       }
+       loop = g_main_loop_new (NULL, FALSE);
+       g_object_weak_ref (G_OBJECT (base_stream), base_stream_unreffed, loop);
+       g_idle_add (unref_stream, stream);
+       g_main_loop_run (loop);
+       g_main_loop_unref (loop);
 
        soup_cache_flush ((SoupCache *)soup_session_get_feature (session, SOUP_TYPE_CACHE));
 


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