diff options
author | Patrick Griffis <pgriffis@igalia.com> | 2022-10-08 12:11:16 -0500 |
---|---|---|
committer | Patrick Griffis <pgriffis@igalia.com> | 2022-10-08 12:13:14 -0500 |
commit | adeddc84df824f2dca4163306a397eb78aec2451 (patch) | |
tree | bb5891c865b4df9054cd94f92635beefde9e7f20 | |
parent | 410e52a4e6ea31e760f114f2320b55419f116701 (diff) | |
download | libsoup-wip/threaded-body-reads.tar.gz |
tests: Add test for threaded http2 body readswip/threaded-body-reads
-rw-r--r-- | tests/http2-test.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/http2-test.c b/tests/http2-test.c index 12012c3b..86d7f59e 100644 --- a/tests/http2-test.c +++ b/tests/http2-test.c @@ -1117,6 +1117,47 @@ do_timeout_test (Test *test, gconstpointer data) g_main_context_iteration (NULL, FALSE); } +static gpointer +thread_read_body (gpointer data) +{ + GInputStream *stream = data; + guint8 buffer[1024]; + GError *error = NULL; + + /* We don't care about the data, we simply want to ensure no criticals are hit. */ + while ((g_input_stream_read (stream, buffer, sizeof (buffer), + NULL, &error)) > 0); + + g_assert_no_error (error); + g_object_unref (stream); + return NULL; +} + +static void +do_threaded_body_read_test (Test *test, gconstpointer data) +{ + GUri *uri; + SoupMessage *msg; + GInputStream *stream; + GThread *threads[20]; + + uri = g_uri_parse_relative (base_uri, "/large", SOUP_HTTP_URI_FLAGS, NULL); + + for (uint i = 0; i < G_N_ELEMENTS (threads); i++) { + msg = soup_message_new_from_uri (SOUP_METHOD_GET, uri); + stream = soup_session_send (test->session, msg, NULL, NULL); + g_assert_nonnull (stream); + g_object_unref (msg); + + threads[i] = g_thread_new (NULL, thread_read_body, stream); + } + + for (uint i = G_N_ELEMENTS (threads) - 1; i > 0; i--) + (void)g_thread_join (threads[i]); + + g_uri_unref (uri); +} + static gboolean unpause_message (SoupServerMessage *msg) { @@ -1358,6 +1399,10 @@ main (int argc, char **argv) setup_session, do_timeout_test, teardown_session); + g_test_add ("/http2/threaded-body-read", Test, NULL, + setup_session, + do_threaded_body_read_test, + teardown_session); ret = g_test_run (); |