[libsoup] cache-test: added a new cancellation test
- From: Sergio Villar Senin <svillar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] cache-test: added a new cancellation test
- Date: Mon, 18 Feb 2013 10:20:22 +0000 (UTC)
commit 054b1e3059f5b9b677d2117ecc3130fa6cd79f1a
Author: Sergio Villar Senin <svillar igalia com>
Date: Fri Feb 15 21:40:37 2013 +0100
cache-test: added a new cancellation test
Added do_refcounting_test that checks that streams do not leak any
reference when a message is cancelled just before starting to read.
This test also need a new cancel flag called
SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH.
https://bugzilla.gnome.org/show_bug.cgi?id=682527
tests/cache-test.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/test-utils.c | 10 ++++++++
tests/test-utils.h | 3 +-
3 files changed, 73 insertions(+), 1 deletions(-)
---
diff --git a/tests/cache-test.c b/tests/cache-test.c
index 9469dc1..d9400fe 100644
--- a/tests/cache-test.c
+++ b/tests/cache-test.c
@@ -550,6 +550,66 @@ do_cancel_test (SoupURI *base_uri)
g_free (body2);
}
+static void
+do_refcounting_test (SoupURI *base_uri)
+{
+ SoupSession *session;
+ SoupCache *cache;
+ char *cache_dir;
+ SoupRequestHTTP *req;
+ GInputStream *stream, *base_stream;
+ SoupURI *uri;
+ GError *error = NULL;
+ guint flags;
+
+ debug_printf (1, "Cache refcounting tests\n");
+
+ cache_dir = g_dir_make_tmp ("cache-test-XXXXXX", NULL);
+ debug_printf (2, " Caching to %s\n", cache_dir);
+ cache = soup_cache_new (cache_dir, SOUP_CACHE_SINGLE_USER);
+ session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
+ SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
+ SOUP_SESSION_ADD_FEATURE, cache,
+ NULL);
+
+ last_request_validated = last_request_hit_network = FALSE;
+ cancelled_requests = 0;
+
+ uri = soup_uri_new_with_base (base_uri, "/1");
+ req = soup_session_request_http_uri (session, "GET", uri, NULL);
+ soup_uri_free (uri);
+
+ flags = SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH | SOUP_TEST_REQUEST_CANCEL_MESSAGE;
+ stream = soup_test_request_send (SOUP_REQUEST (req), NULL, flags, &error);
+ if (!stream) {
+ debug_printf (1, " could not send request: %s\n",
+ error->message);
+ g_error_free (error);
+ g_object_unref (req);
+ return;
+ }
+
+ 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);
+ }
+
+ soup_cache_flush ((SoupCache *)soup_session_get_feature (session, SOUP_TYPE_CACHE));
+
+ soup_test_session_abort_unref (session);
+
+ g_object_unref (cache);
+ g_free (cache_dir);
+}
+
int
main (int argc, char **argv)
{
@@ -565,6 +625,7 @@ main (int argc, char **argv)
do_basics_test (base_uri);
do_cancel_test (base_uri);
+ do_refcounting_test (base_uri);
soup_uri_free (base_uri);
soup_test_server_quit_unref (server);
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 754b84a..a2c24cf 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -469,6 +469,16 @@ soup_test_request_send (SoupRequest *req,
stream = soup_request_send_finish (req, data.result, error);
+ if (cancel_data && (flags & SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH)) {
+ GMainContext *context;
+
+ cancel_message_or_cancellable (cancel_data);
+
+ context = g_main_loop_get_context (data.loop);
+ while (g_main_context_pending (context))
+ g_main_context_iteration (context, FALSE);
+ }
+
g_main_loop_unref (data.loop);
g_object_unref (data.result);
diff --git a/tests/test-utils.h b/tests/test-utils.h
index e7782ee..b7b2195 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -28,7 +28,8 @@ typedef enum {
SOUP_TEST_REQUEST_CANCEL_MESSAGE = (1 << 0),
SOUP_TEST_REQUEST_CANCEL_CANCELLABLE = (1 << 1),
SOUP_TEST_REQUEST_CANCEL_SOON = (1 << 2),
- SOUP_TEST_REQUEST_CANCEL_IMMEDIATE = (1 << 3)
+ SOUP_TEST_REQUEST_CANCEL_IMMEDIATE = (1 << 3),
+ SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH = (1 << 4),
} SoupTestRequestFlags;
SoupSession *soup_test_session_new (GType type, ...);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]