diff options
author | Dan Winship <danw@gnome.org> | 2013-08-23 13:34:37 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2013-08-23 13:34:37 -0400 |
commit | 164e49a27eeeedca800f466b0b14a4e61a162007 (patch) | |
tree | 43cf1eac4acd6dcc0924a7752178cdea8e4e29cf | |
parent | 9eb7ad6ab119d17020e56e6606d6720ccaf1ba1f (diff) | |
download | libsoup-164e49a27eeeedca800f466b0b14a4e61a162007.tar.gz |
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
-rw-r--r-- | 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 34389f8e..a8d01ebf 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)); |