[libsoup/carlosgc/status: 4/6] Stop using soup_session_cancel_message() in tests




commit 3a81fb952820612ccc6e1e90a0bdca49c7ede555
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Sun Nov 15 14:23:23 2020 +0100

    Stop using soup_session_cancel_message() in tests

 tests/auth-test.c         | 31 ++++++++------------
 tests/cache-test.c        | 20 +++----------
 tests/connection-test.c   | 10 ++++---
 tests/continue-test.c     |  2 +-
 tests/misc-test.c         | 49 ++++++++++++++++---------------
 tests/range-test.c        |  4 +--
 tests/redirect-test.c     |  2 +-
 tests/request-body-test.c |  2 +-
 tests/server-test.c       | 16 +++++------
 tests/session-test.c      | 12 +++++---
 tests/sniffing-test.c     |  6 ++--
 tests/ssl-test.c          |  4 +--
 tests/streaming-test.c    |  2 +-
 tests/test-utils.c        | 73 +++++++++++------------------------------------
 tests/test-utils.h        | 25 ++++++++--------
 15 files changed, 103 insertions(+), 155 deletions(-)
---
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 5b8d354f..cf0c59a3 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -1065,7 +1065,7 @@ do_auth_close_test (void)
        g_signal_connect (acd.msg, "authenticate",
                          G_CALLBACK (auth_close_authenticate), &acd);
        g_uri_unref (uri);
-       body = soup_test_session_async_send (acd.session, acd.msg, NULL);
+       body = soup_test_session_async_send (acd.session, acd.msg, NULL, NULL);
 
        soup_test_assert_message_status (acd.msg, SOUP_STATUS_OK);
 
@@ -1189,7 +1189,7 @@ do_disappearing_auth_test (void)
        g_signal_connect (msg, "authenticate",
                          G_CALLBACK (disappear_authenticate), &counter);
 
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
 
        soup_test_assert (counter <= 2,
                          "Got stuck in loop");
@@ -1522,20 +1522,14 @@ do_message_has_authorization_header_test (void)
        soup_test_session_abort_unref (session);
 }
 
-typedef struct {
-       SoupSession *session;
-       GCancellable *cancellable;
-} CancelAfterRetryData;
-
 static gboolean
-cancel_after_retry_authenticate (SoupMessage          *msg,
-                                 SoupAuth             *auth,
-                                 gboolean              retrying,
-                                 CancelAfterRetryData *data)
+cancel_after_retry_authenticate (SoupMessage  *msg,
+                                 SoupAuth     *auth,
+                                 gboolean      retrying,
+                                 GCancellable *cancellable)
 {
         if (retrying) {
-                soup_session_cancel_message (data->session, msg, 0);
-                g_cancellable_cancel (data->cancellable);
+                g_cancellable_cancel (cancellable);
 
                return FALSE;
        }
@@ -1566,14 +1560,13 @@ do_cancel_after_retry_test (void)
         SoupSession *session;
         SoupMessage *msg;
         char *uri;
-       CancelAfterRetryData data;
+       GCancellable *cancellable;
         GMainLoop *loop;
 
         SOUP_TEST_SKIP_IF_NO_APACHE;
 
         session = soup_test_session_new (NULL);
-       data.session = session;
-        data.cancellable = g_cancellable_new ();
+        cancellable = g_cancellable_new ();
 
         loop = g_main_loop_new (NULL, FALSE);
 
@@ -1581,13 +1574,13 @@ do_cancel_after_retry_test (void)
         msg = soup_message_new ("GET", uri);
        g_signal_connect (msg, "authenticate",
                           G_CALLBACK (cancel_after_retry_authenticate),
-                          &data);
-        soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, data.cancellable,
+                          cancellable);
+        soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, cancellable,
                                 (GAsyncReadyCallback)request_send_cb, loop);
         g_main_loop_run (loop);
 
         g_object_unref (msg);
-        g_object_unref (data.cancellable);
+        g_object_unref (cancellable);
         g_free (uri);
         soup_test_session_abort_unref (session);
 }
diff --git a/tests/cache-test.c b/tests/cache-test.c
index 0792753f..ce0a077b 100644
--- a/tests/cache-test.c
+++ b/tests/cache-test.c
@@ -232,7 +232,7 @@ do_request_with_cancel (SoupSession          *session,
        uri = g_uri_parse_relative (base_uri, path, SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri (method, uri);
        g_uri_unref (uri);
-       cancellable = flags & SOUP_TEST_REQUEST_CANCEL_CANCELLABLE ? g_cancellable_new () : NULL;
+       cancellable = g_cancellable_new ();
        stream = soup_test_request_send (session, msg, cancellable, flags, &error);
        if (stream) {
                debug_printf (1, "    could not cancel the request\n");
@@ -502,14 +502,8 @@ do_cancel_test (gconstpointer data)
                            NULL);
 
        /* Check that messages are correctly processed on cancellations. */
-       debug_printf (1, "  Cancel fresh resource with soup_session_message_cancel()\n");
-       flags = SOUP_TEST_REQUEST_CANCEL_MESSAGE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
-       do_request_with_cancel (session, base_uri, "GET", "/1", flags);
-       soup_test_assert (last_request_unqueued,
-                         "Cancelled request /1 not unqueued");
-
        debug_printf (1, "  Cancel fresh resource with g_cancellable_cancel()\n");
-       flags = SOUP_TEST_REQUEST_CANCEL_CANCELLABLE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
+       flags = SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
        do_request_with_cancel (session, base_uri, "GET", "/1", flags);
        soup_test_assert (last_request_unqueued,
                          "Cancelled request /1 not unqueued");
@@ -523,14 +517,8 @@ do_cancel_test (gconstpointer data)
                          G_CALLBACK (request_unqueued), NULL);
 
        /* Check that messages are correctly processed on cancellations. */
-       debug_printf (1, "  Cancel a revalidating resource with soup_session_message_cancel()\n");
-       flags = SOUP_TEST_REQUEST_CANCEL_MESSAGE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
-       do_request_with_cancel (session, base_uri, "GET", "/2", flags);
-       soup_test_assert (last_request_unqueued,
-                         "Cancelled request /2 not unqueued");
-
        debug_printf (1, "  Cancel a revalidating resource with g_cancellable_cancel()\n");
-       flags = SOUP_TEST_REQUEST_CANCEL_CANCELLABLE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
+       flags = SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
        do_request_with_cancel (session, base_uri, "GET", "/2", flags);
        soup_test_assert (last_request_unqueued,
                          "Cancelled request /2 not unqueued");
@@ -584,7 +572,7 @@ do_refcounting_test (gconstpointer data)
        msg = soup_message_new_from_uri ("GET", uri);
        g_uri_unref (uri);
 
-       flags = SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH | SOUP_TEST_REQUEST_CANCEL_MESSAGE;
+       flags = SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH;
        stream = soup_test_request_send (session, msg, NULL, flags, &error);
        if (!stream) {
                debug_printf (1, "    could not send request: %s\n",
diff --git a/tests/connection-test.c b/tests/connection-test.c
index fea3aa38..34981705 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -464,11 +464,13 @@ do_max_conns_test_for_session (SoupSession *session)
 {
        SoupMessage *msgs[TEST_CONNS];
        int i;
+       GCancellable *cancellable;
 
        max_conns_loop = g_main_loop_new (NULL, TRUE);
 
        g_mutex_lock (&server_mutex);
 
+       cancellable = g_cancellable_new ();
        g_signal_connect (session, "request-queued",
                          G_CALLBACK (max_conns_request_queued), NULL);
        msgs_done = 0;
@@ -476,7 +478,7 @@ do_max_conns_test_for_session (SoupSession *session)
                msgs[i] = soup_message_new_from_uri ("GET", base_uri);
                g_signal_connect (msgs[i], "finished",
                                  G_CALLBACK (max_conns_message_complete), NULL);
-               soup_session_send_async (session, msgs[i], G_PRIORITY_DEFAULT, NULL, NULL, NULL);
+               soup_session_send_async (session, msgs[i], G_PRIORITY_DEFAULT, cancellable, NULL, NULL);
        }
 
        g_main_loop_run (max_conns_loop);
@@ -503,11 +505,11 @@ do_max_conns_test_for_session (SoupSession *session)
                /* Clean up so we don't get a spurious "Leaked
                 * session" error.
                 */
-               for (i = 0; i < TEST_CONNS; i++)
-                       soup_session_cancel_message (session, msgs[i], 0);
+               g_cancellable_cancel (cancellable);
                g_main_loop_run (max_conns_loop);
        }
 
+       g_object_unref (cancellable);
        g_main_loop_unref (max_conns_loop);
        if (quit_loop_timeout) {
                g_source_remove (quit_loop_timeout);
@@ -728,7 +730,7 @@ do_one_connection_state_test (SoupSession         *session,
        g_signal_connect (msg, "network-event",
                          G_CALLBACK (message_network_event),
                          state);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_bytes_unref (body);
        g_object_unref (msg);
diff --git a/tests/continue-test.c b/tests/continue-test.c
index 4f0666cd..cc1da185 100644
--- a/tests/continue-test.c
+++ b/tests/continue-test.c
@@ -134,7 +134,7 @@ do_message (const char *path, gboolean long_body,
        events = NULL;
        session = soup_test_session_new (NULL);
         g_assert (SOUP_IS_MESSAGE (msg));
-       response_body = soup_test_session_async_send (session, msg, NULL);
+       response_body = soup_test_session_async_send (session, msg, NULL, NULL);
         g_assert (SOUP_IS_MESSAGE (msg));
        soup_test_session_abort_unref (session);
         g_assert (SOUP_IS_MESSAGE (msg));
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 8f19aca2..80ee111e 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -307,14 +307,14 @@ do_msg_reuse_test (void)
        msg = soup_message_new_from_uri ("GET", base_uri);
        g_signal_connect (msg, "authenticate",
                           G_CALLBACK (reuse_test_authenticate), NULL);
-       soup_test_session_async_send (session, msg, NULL);
+       soup_test_session_async_send (session, msg, NULL, NULL);
        ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
 
        debug_printf (1, "  Redirect message\n");
        uri = g_uri_parse_relative (base_uri, "/redirect", SOUP_HTTP_URI_FLAGS, NULL);
        soup_message_set_uri (msg, uri);
        g_uri_unref (uri);
-       soup_test_session_async_send (session, msg, NULL);
+       soup_test_session_async_send (session, msg, NULL, NULL);
        g_assert_true (soup_uri_equal (soup_message_get_uri (msg), base_uri));
        ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
 
@@ -322,10 +322,10 @@ do_msg_reuse_test (void)
        uri = g_uri_parse_relative (base_uri, "/auth", SOUP_HTTP_URI_FLAGS, NULL);
        soup_message_set_uri (msg, uri);
        g_uri_unref (uri);
-       soup_test_session_async_send (session, msg, NULL);
+       soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        soup_message_set_uri (msg, base_uri);
-       soup_test_session_async_send (session, msg, NULL);
+       soup_test_session_async_send (session, msg, NULL, NULL);
        ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
 
        soup_test_session_abort_unref (session);
@@ -371,9 +371,10 @@ ea_message_network_event (SoupMessage       *msg,
 }
 
 static void
-ea_message_starting (SoupMessage *msg, SoupSession *session)
+ea_message_starting (SoupMessage  *msg,
+                    GCancellable *cancellable)
 {
-       soup_session_cancel_message (session, msg, 0);
+       g_cancellable_cancel (cancellable);
 }
 
 static void
@@ -381,6 +382,7 @@ do_early_abort_test (void)
 {
        SoupSession *session;
        SoupMessage *msg;
+       GCancellable *cancellable;
        GMainContext *context;
        GMainLoop *loop;
        GError *error = NULL;
@@ -411,7 +413,7 @@ do_early_abort_test (void)
        g_signal_connect (msg, "network-event",
                          G_CALLBACK (ea_message_network_event),
                          session);
-       g_assert_null (soup_test_session_async_send (session, msg, &error));
+       g_assert_null (soup_test_session_async_send (session, msg, NULL, &error));
        debug_printf (2, "  Message 2 completed\n");
 
        g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
@@ -427,14 +429,16 @@ do_early_abort_test (void)
 
        session = soup_test_session_new (NULL);
        msg = soup_message_new_from_uri ("GET", base_uri);
+       cancellable = g_cancellable_new ();
 
        g_signal_connect (msg, "starting",
-                         G_CALLBACK (ea_message_starting), session);
-       g_assert_null (soup_test_session_async_send (session, msg, &error));
+                         G_CALLBACK (ea_message_starting), cancellable);
+       g_assert_null (soup_test_session_async_send (session, msg, cancellable, &error));
        debug_printf (2, "  Message 3 completed\n");
 
        g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
        g_clear_error (&error);
+       g_object_unref (cancellable);
        g_object_unref (msg);
 
        while (g_main_context_pending (context))
@@ -485,13 +489,9 @@ do_accept_language_test (void)
 }
 
 static gboolean
-cancel_message_timeout (gpointer msg)
+cancel_message_timeout (GCancellable *cancellable)
 {
-       SoupSession *session = g_object_get_data (G_OBJECT (msg), "session");
-
-       soup_session_cancel_message (session, msg, 0);
-       g_object_unref (msg);
-       g_object_unref (session);
+       g_cancellable_cancel (cancellable);
        return FALSE;
 }
 
@@ -500,20 +500,23 @@ do_cancel_while_reading_test_for_session (SoupSession *session)
 {
        SoupMessage *msg;
        GUri *uri;
+       GCancellable *cancellable;
        GError *error = NULL;
 
        uri = g_uri_parse_relative (base_uri, "/slow", SOUP_HTTP_URI_FLAGS, NULL);
        msg = soup_message_new_from_uri ("GET", uri);
        g_uri_unref (uri);
 
-       g_object_set_data (G_OBJECT (msg), "session", session);
-       g_object_ref (msg);
-       g_object_ref (session);
-       g_timeout_add (100, cancel_message_timeout, msg);
+       cancellable = g_cancellable_new ();
+       g_timeout_add_full (G_PRIORITY_DEFAULT, 100,
+                           (GSourceFunc)cancel_message_timeout,
+                           g_object_ref (cancellable),
+                           g_object_unref);
 
-       g_assert_null (soup_test_session_async_send (session, msg, &error));
+       g_assert_null (soup_test_session_async_send (session, msg, cancellable, &error));
        g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
        g_clear_error (&error);
+       g_object_unref (cancellable);
        g_object_unref (msg);
 }
 
@@ -560,7 +563,7 @@ do_cancel_while_reading_immediate_req_test (void)
 
        g_test_bug ("692310");
 
-       flags = SOUP_TEST_REQUEST_CANCEL_CANCELLABLE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
+       flags = SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
 
        session = soup_test_session_new (NULL);
        do_cancel_while_reading_req_test_for_session (session, flags);
@@ -573,7 +576,7 @@ do_cancel_while_reading_delayed_req_test (void)
        SoupSession *session;
        guint flags;
 
-       flags = SOUP_TEST_REQUEST_CANCEL_CANCELLABLE | SOUP_TEST_REQUEST_CANCEL_SOON;
+       flags = SOUP_TEST_REQUEST_CANCEL_SOON;
 
        session = soup_test_session_new (NULL);
        do_cancel_while_reading_req_test_for_session (session, flags);
@@ -588,7 +591,7 @@ do_cancel_while_reading_preemptive_req_test (void)
 
        g_test_bug ("637039");
 
-       flags = SOUP_TEST_REQUEST_CANCEL_CANCELLABLE | SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE;
+       flags = SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE;
 
        session = soup_test_session_new (NULL);
        do_cancel_while_reading_req_test_for_session (session, flags);
diff --git a/tests/range-test.c b/tests/range-test.c
index 08ca88bc..ed220028 100644
--- a/tests/range-test.c
+++ b/tests/range-test.c
@@ -69,7 +69,7 @@ do_single_range (SoupSession *session, SoupMessage *msg,
        debug_printf (1, "    Range: %s\n",
                      soup_message_headers_get_one (soup_message_get_request_headers (msg), "Range"));
 
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
 
        if (!succeed) {
                soup_test_assert_message_status (msg, SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE);
@@ -120,7 +120,7 @@ do_multi_range (SoupSession *session, SoupMessage *msg,
        debug_printf (1, "    Range: %s\n",
                      soup_message_headers_get_one (soup_message_get_request_headers (msg), "Range"));
 
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
 
        soup_test_assert_message_status (msg, SOUP_STATUS_PARTIAL_CONTENT);
 
diff --git a/tests/redirect-test.c b/tests/redirect-test.c
index 0e7e996f..a7e15cd9 100644
--- a/tests/redirect-test.c
+++ b/tests/redirect-test.c
@@ -191,7 +191,7 @@ do_message_api_test (SoupSession *session, TestCase *test)
        g_signal_connect (msg, "restarted",
                          G_CALLBACK (restarted), &treq);
 
-       body = soup_test_session_async_send (session, msg, &error);
+       body = soup_test_session_async_send (session, msg, NULL, &error);
 
        soup_test_assert_message_status (msg, test->final_status);
        if (test->error_code)
diff --git a/tests/request-body-test.c b/tests/request-body-test.c
index c6227f00..aa49f9a9 100644
--- a/tests/request-body-test.c
+++ b/tests/request-body-test.c
@@ -119,7 +119,7 @@ do_request_test (gconstpointer data)
                           G_CALLBACK (wrote_body_data), &ptd);
 
         if (flags & ASYNC)
-                soup_test_session_async_send (session, msg, NULL);
+                soup_test_session_async_send (session, msg, NULL, NULL);
         else
                 soup_test_session_send_message (session, msg);
         soup_test_assert_message_status (msg, SOUP_STATUS_CREATED);
diff --git a/tests/server-test.c b/tests/server-test.c
index 94fa142b..f2ea4584 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -409,7 +409,7 @@ do_ipv6_test (ServerData *sd, gconstpointer test_data)
 
        debug_printf (1, "  HTTP/1.1\n");
        msg = soup_message_new_from_uri ("GET", sd->base_uri);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_bytes_unref (body);
        g_object_unref (msg);
@@ -417,7 +417,7 @@ do_ipv6_test (ServerData *sd, gconstpointer test_data)
        debug_printf (1, "  HTTP/1.0\n");
        msg = soup_message_new_from_uri ("GET", sd->base_uri);
        soup_message_set_http_version (msg, SOUP_HTTP_1_0);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_bytes_unref (body);
        g_object_unref (msg);
@@ -470,7 +470,7 @@ do_multi_test (ServerData *sd, GUri *uri1, GUri *uri2)
 
        uristr = g_uri_to_string (uri1);
        msg = soup_message_new ("GET", uristr);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_assert_cmpmem (uristr, strlen (uristr), g_bytes_get_data (body, NULL), g_bytes_get_size (body));
        g_bytes_unref (body);
@@ -479,7 +479,7 @@ do_multi_test (ServerData *sd, GUri *uri1, GUri *uri2)
 
        uristr = g_uri_to_string (uri2);
        msg = soup_message_new ("GET", uristr);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_assert_cmpmem (uristr, strlen (uristr), g_bytes_get_data (body, NULL), g_bytes_get_size (body));
        g_bytes_unref (body);
@@ -650,7 +650,7 @@ do_gsocket_import_test (void)
 
        session = soup_test_session_new (NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_bytes_unref (body);
        g_object_unref (msg);
@@ -716,7 +716,7 @@ do_fd_import_test (void)
 
        session = soup_test_session_new (NULL);
        msg = soup_message_new_from_uri ("GET", uri);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_bytes_unref (body);
        g_object_unref (msg);
@@ -923,7 +923,7 @@ do_fail_404_test (ServerData *sd, gconstpointer test_data)
 
        session = soup_test_session_new (NULL);
        msg = soup_message_new_from_uri ("GET", sd->base_uri);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_NOT_FOUND);
        g_bytes_unref (body);
        g_object_unref (msg);
@@ -950,7 +950,7 @@ do_fail_500_test (ServerData *sd, gconstpointer pause)
        msg = soup_message_new_from_uri ("GET", sd->base_uri);
        if (pause)
                soup_message_headers_append (soup_message_get_request_headers (msg), "X-Test-Server-Pause", 
"true");
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
        g_bytes_unref (body);
        g_object_unref (msg);
diff --git a/tests/session-test.c b/tests/session-test.c
index 34a0f539..9053f37b 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -57,9 +57,10 @@ finished_cb (SoupMessage *msg,
 }
 
 static void
-cancel_message_cb (SoupMessage *msg, gpointer session)
+cancel_message_cb (SoupMessage  *msg,
+                  GCancellable *cancellable)
 {
-       soup_session_cancel_message (session, msg, 0);
+       g_cancellable_cancel (cancellable);
 }
 
 static void
@@ -81,6 +82,7 @@ do_test_for_session (SoupSession *session,
        guint timeout_id;
        GUri *timeout_uri;
        GBytes *body;
+       GCancellable *cancellable;
        GError *error = NULL;
 
        debug_printf (1, "  queue_message\n");
@@ -141,11 +143,12 @@ do_test_for_session (SoupSession *session,
 
        debug_printf (1, "  cancel_message\n");
        msg = soup_message_new_from_uri ("GET", base_uri);
-       soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL,
+       cancellable = g_cancellable_new ();
+       soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, cancellable,
                                 (GAsyncReadyCallback)cancel_message_send_done,
                                 &error);
        g_signal_connect (msg, "wrote-headers",
-                         G_CALLBACK (cancel_message_cb), session);
+                         G_CALLBACK (cancel_message_cb), cancellable);
 
        loop = g_main_loop_new (NULL, FALSE);
        g_main_loop_run (loop);
@@ -154,6 +157,7 @@ do_test_for_session (SoupSession *session,
 
        g_main_loop_unref (loop);
        g_clear_error (&error);
+       g_object_unref (cancellable);
        g_object_unref (msg);
 }
 
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c
index 19f23f1c..45338459 100644
--- a/tests/sniffing-test.c
+++ b/tests/sniffing-test.c
@@ -211,7 +211,7 @@ do_signals_test (gboolean should_content_sniff,
                          "signal::content_sniffed", content_sniffed, NULL,
                          NULL);
 
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
 
        if (should_content_sniff) {
                soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") != NULL,
@@ -300,7 +300,7 @@ test_sniffing (const char *path, const char *expected_type)
        g_signal_connect (msg, "content-sniffed",
                          G_CALLBACK (sniffing_content_sniffed), &sniffed_type);
 
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        g_assert_cmpstr (sniffed_type, ==, expected_type);
        g_free (sniffed_type);
        g_bytes_unref (body);
@@ -352,7 +352,7 @@ test_disabled (gconstpointer data)
        g_signal_connect (msg, "content-sniffed",
                          G_CALLBACK (sniffing_content_sniffed), &sniffed_type);
 
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
 
        g_assert_null (sniffed_type);
        g_bytes_unref (body);
diff --git a/tests/ssl-test.c b/tests/ssl-test.c
index ed018488..2845494b 100644
--- a/tests/ssl-test.c
+++ b/tests/ssl-test.c
@@ -224,7 +224,7 @@ do_tls_interaction_test (void)
 
        /* Without a GTlsInteraction */
        msg = soup_message_new_from_uri ("GET", test_uri);
-       body = soup_test_session_async_send (session, msg, &error);
+       body = soup_test_session_async_send (session, msg, NULL, &error);
        g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_CERTIFICATE_REQUIRED);
        g_clear_error (&error);
        g_bytes_unref (body);
@@ -238,7 +238,7 @@ do_tls_interaction_test (void)
 
        /* With a GTlsInteraction */
        msg = soup_message_new_from_uri ("GET", test_uri);
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_assert_nonnull (soup_message_get_tls_certificate (msg));
        g_bytes_unref (body);
diff --git a/tests/streaming-test.c b/tests/streaming-test.c
index 7c2ff1e4..42e9b4ea 100644
--- a/tests/streaming-test.c
+++ b/tests/streaming-test.c
@@ -93,7 +93,7 @@ do_request (SoupSession *session, GUri *base_uri, char *path)
        msg = soup_message_new_from_uri ("GET", uri);
        g_uri_unref (uri);
 
-       body = soup_test_session_async_send (session, msg, NULL);
+       body = soup_test_session_async_send (session, msg, NULL, NULL);
 
        soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_assert_cmpint (g_bytes_get_size (body), ==, g_bytes_get_size (full_response));
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 9627d892..e3de265c 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -340,9 +340,10 @@ on_message_finished (SoupMessage *msg,
 }
 
 GBytes *
-soup_test_session_async_send (SoupSession *session,
-                             SoupMessage *msg,
-                             GError     **error)
+soup_test_session_async_send (SoupSession  *session,
+                             SoupMessage  *msg,
+                             GCancellable *cancellable,
+                             GError      **error)
 {
        gboolean message_finished = FALSE;
        GMainContext *async_context = g_main_context_ref_thread_default ();
@@ -352,7 +353,7 @@ soup_test_session_async_send (SoupSession *session,
        signal_id = g_signal_connect (msg, "finished",
                                      G_CALLBACK (on_message_finished), &message_finished);
 
-       soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL,
+       soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, cancellable,
                                 (GAsyncReadyCallback)send_async_ready_cb, &data);
 
        while (!data.done || !message_finished)
@@ -660,53 +661,10 @@ async_as_sync_callback (GObject      *object,
        g_main_loop_quit (data->loop);
 }
 
-typedef struct {
-       SoupSession *session;
-       SoupMessage  *msg;
-       GCancellable *cancellable;
-       SoupTestRequestFlags flags;
-} CancelData;
-
-static CancelData *
-create_cancel_data (SoupSession          *session,
-                   SoupMessage          *msg,
-                   GCancellable         *cancellable,
-                   SoupTestRequestFlags  flags)
-{
-       CancelData *cancel_data;
-
-       if (!flags)
-               return NULL;
-
-       cancel_data = g_slice_new0 (CancelData);
-       cancel_data->flags = flags;
-       if (flags & SOUP_TEST_REQUEST_CANCEL_MESSAGE) {
-               cancel_data->session = session;
-               cancel_data->msg = g_object_ref (msg);
-       } else if (flags & SOUP_TEST_REQUEST_CANCEL_CANCELLABLE)
-               cancel_data->cancellable = g_object_ref (cancellable);
-       return cancel_data;
-}
-
-inline static void
-cancel_message_or_cancellable (CancelData *cancel_data)
-{
-       if (cancel_data->flags & SOUP_TEST_REQUEST_CANCEL_MESSAGE) {
-               SoupMessage *msg = cancel_data->msg;
-
-               soup_session_cancel_message (cancel_data->session, msg, 0);
-               g_object_unref (msg);
-       } else if (cancel_data->flags & SOUP_TEST_REQUEST_CANCEL_CANCELLABLE) {
-               g_cancellable_cancel (cancel_data->cancellable);
-               g_object_unref (cancel_data->cancellable);
-       }
-       g_slice_free (CancelData, cancel_data);
-}
-
 static gboolean
-cancel_request_timeout (gpointer data)
+cancel_request_timeout (GCancellable *cancellable)
 {
-       cancel_message_or_cancellable ((CancelData *) data);
+       g_cancellable_cancel (cancellable);
        return FALSE;
 }
 
@@ -719,26 +677,27 @@ soup_test_request_send (SoupSession   *session,
 {
        AsyncAsSyncData data;
        GInputStream *stream;
-       CancelData *cancel_data = create_cancel_data (session, msg, cancellable, flags);
 
        data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
-       if (cancel_data &&
-           (flags & SOUP_TEST_REQUEST_CANCEL_SOON || flags & SOUP_TEST_REQUEST_CANCEL_IMMEDIATE)) {
+       if (flags & SOUP_TEST_REQUEST_CANCEL_SOON || flags & SOUP_TEST_REQUEST_CANCEL_IMMEDIATE) {
                guint interval = flags & SOUP_TEST_REQUEST_CANCEL_SOON ? 100 : 0;
-               g_timeout_add_full (G_PRIORITY_HIGH, interval, cancel_request_timeout, cancel_data, NULL);
+               g_timeout_add_full (G_PRIORITY_HIGH, interval,
+                                   (GSourceFunc)cancel_request_timeout,
+                                   g_object_ref (cancellable), g_object_unref);
        }
-       if (cancel_data && (flags & SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE))
-               cancel_message_or_cancellable (cancel_data);
+       if (flags & SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE)
+               g_cancellable_cancel (cancellable);
+
        soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, cancellable,
                                 async_as_sync_callback, &data);
        g_main_loop_run (data.loop);
 
        stream = soup_session_send_finish (session, data.result, error);
 
-       if (cancel_data && (flags &  SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH)) {
+       if (flags & SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH) {
                GMainContext *context;
 
-               cancel_message_or_cancellable (cancel_data);
+               g_cancellable_cancel (cancellable);
 
                context = g_main_loop_get_context (data.loop);
                while (g_main_context_pending (context))
diff --git a/tests/test-utils.h b/tests/test-utils.h
index 0447f73f..d83e2639 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -43,21 +43,20 @@ gboolean have_curl (void);
 
 typedef enum {
        SOUP_TEST_REQUEST_NONE = 0,
-       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_PREEMPTIVE = (1 << 4),
-       SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH = (1 << 5),
+       SOUP_TEST_REQUEST_CANCEL_SOON = (1 << 0),
+       SOUP_TEST_REQUEST_CANCEL_IMMEDIATE = (1 << 1),
+       SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE = (1 << 2),
+       SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH = (1 << 3),
 } SoupTestRequestFlags;
 
-SoupSession *soup_test_session_new                (const char *propname, ...);
-void         soup_test_session_abort_unref        (SoupSession *session);
-GBytes      *soup_test_session_async_send         (SoupSession *session,
-                                                  SoupMessage *msg,
-                                                  GError     **error);
-guint        soup_test_session_send_message       (SoupSession *session,
-                                                  SoupMessage *msg);
+SoupSession *soup_test_session_new                (const char   *propname, ...);
+void         soup_test_session_abort_unref        (SoupSession  *session);
+GBytes      *soup_test_session_async_send         (SoupSession  *session,
+                                                  SoupMessage  *msg,
+                                                  GCancellable *cancellable,
+                                                  GError      **error);
+guint        soup_test_session_send_message       (SoupSession  *session,
+                                                  SoupMessage  *msg);
 
 typedef enum {
        SOUP_TEST_SERVER_DEFAULT             = 0,


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