[libsoup/wip/http2] http2: Add cancellation test
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/wip/http2] http2: Add cancellation test
- Date: Fri, 14 May 2021 18:58:33 +0000 (UTC)
commit 4541288f8cd4fd1f2e5b530d83b6149a4b71edfc
Author: Patrick Griffis <pgriffis igalia com>
Date: Fri May 14 13:58:23 2021 -0500
http2: Add cancellation test
tests/http2-test.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
---
diff --git a/tests/http2-test.c b/tests/http2-test.c
index 2151ab73..f7828bfc 100644
--- a/tests/http2-test.c
+++ b/tests/http2-test.c
@@ -171,6 +171,46 @@ do_multi_message_async_test (Test *test, gconstpointer data)
g_main_context_unref (async_context);
}
+
+static void
+on_send_and_read_complete (GObject *source, GAsyncResult *res, gpointer user_data)
+{
+ SoupSession *sess = SOUP_SESSION (source);
+ gboolean *done = user_data;
+ GError *error = NULL;
+ GBytes *response = soup_session_send_and_read_finish (sess, res, &error);
+
+ g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
+ g_assert_null (response);
+ *done = TRUE;
+}
+
+static void
+do_cancellation_test (Test *test, gconstpointer data)
+{
+ test->msg = soup_message_new (SOUP_METHOD_GET, "https://127.0.0.1:5000/large");
+ GMainContext *async_context = g_main_context_ref_thread_default ();
+ GCancellable *cancellable = g_cancellable_new ();
+ gboolean done = FALSE;
+
+ soup_session_send_and_read_async (test->session, test->msg, G_PRIORITY_DEFAULT, cancellable,
+ on_send_and_read_complete, &done);
+
+ /* Just iterate until a partial read is happening */
+ for (guint i = 100000; i; i--)
+ g_main_context_iteration (async_context, FALSE);
+
+ /* Then cancel everything */
+ g_cancellable_cancel (cancellable);
+
+ while (!done)
+ g_main_context_iteration (async_context, FALSE);
+
+ g_object_unref (test->msg);
+ g_object_unref (cancellable);
+ g_main_context_unref (async_context);
+}
+
static void
do_post_sync_test (Test *test, gconstpointer data)
{
@@ -581,6 +621,12 @@ main (int argc, char **argv)
setup_session,
do_preconnect_test,
teardown_session);
+ g_test_add ("/http2/cancellation", Test, NULL,
+ setup_session,
+ do_cancellation_test,
+ teardown_session);
+
+
ret = g_test_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]