diff options
| author | Carlos Garcia Campos <cgarcia@igalia.com> | 2020-10-27 13:50:01 +0100 |
|---|---|---|
| committer | Carlos Garcia Campos <cgarcia@igalia.com> | 2020-10-27 13:50:01 +0100 |
| commit | 0eb17ab6484b9ba0dcd34864ef73dbbf26bc3113 (patch) | |
| tree | 7489190d4feddea044e1432f15a75fb811c6b9bf | |
| parent | bf95e5100ff3f59f846d65c18c33ee29d06a5c7c (diff) | |
| download | libsoup-0eb17ab6484b9ba0dcd34864ef73dbbf26bc3113.tar.gz | |
tests: stop using soup_session_pause/unpause_message in tests
Remove the tests checking old api that has already been removed.
| -rw-r--r-- | libsoup/soup-message.c | 17 | ||||
| -rw-r--r-- | tests/meson.build | 1 | ||||
| -rw-r--r-- | tests/misc-test.c | 104 | ||||
| -rw-r--r-- | tests/pull-api-test.c | 256 | ||||
| -rw-r--r-- | tests/sniffing-test.c | 102 |
5 files changed, 14 insertions, 466 deletions
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c index a9805aa6..039f872b 100644 --- a/libsoup/soup-message.c +++ b/libsoup/soup-message.c @@ -399,26 +399,13 @@ soup_message_class_init (SoupMessageClass *message_class) * @type: the content type that we got from sniffing * @params: (element-type utf8 utf8): a #GHashTable with the parameters * - * This signal is emitted after #SoupMessage::got-headers, and - * before the first #SoupMessage::got-chunk. If content - * sniffing is disabled, or no content sniffing will be + * This signal is emitted after #SoupMessage::got-headers. + * If content sniffing is disabled, or no content sniffing will be * performed, due to the sniffer deciding to trust the * Content-Type sent by the server, this signal is emitted * immediately after #SoupMessage::got-headers, and @type is * %NULL. * - * If the #SoupContentSniffer feature is enabled, and the - * sniffer decided to perform sniffing, the first - * #SoupMessage::got-chunk emission may be delayed, so that the - * sniffer has enough data to correctly sniff the content. It - * notified the library user that the content has been - * sniffed, and allows it to change the header contents in the - * message, if desired. - * - * After this signal is emitted, the data that was spooled so - * that sniffing could be done is delivered on the first - * emission of #SoupMessage::got-chunk. - * * Since: 2.28 **/ signals[CONTENT_SNIFFED] = diff --git a/tests/meson.build b/tests/meson.build index 1adeb167..c3346ed7 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -86,7 +86,6 @@ if have_apache ['connection', false, []], ['range', false, []], ['proxy', false, []], - ['pull-api', false, []], ] configure_file(output : 'httpd.conf', diff --git a/tests/misc-test.c b/tests/misc-test.c index 56f5ab44..39247ba5 100644 --- a/tests/misc-test.c +++ b/tests/misc-test.c @@ -662,108 +662,6 @@ do_aliases_test (void) soup_test_session_abort_unref (session); } -static void -do_pause_abort_test (void) -{ - SoupSession *session; - SoupMessage *msg; - gpointer ptr; - - g_test_bug ("673905"); - - g_test_skip ("FIXME: Session has 1 ref at the end, SessionAsync had a different clear_message function with different semantics."); - return; - - session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); - - msg = soup_message_new_from_uri ("GET", base_uri); - soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); - soup_session_pause_message (session, msg); - - g_object_add_weak_pointer (G_OBJECT (msg), &ptr); - g_object_unref (msg); - soup_test_session_abort_unref (session); - - g_assert_null (ptr); -} - -static GMainLoop *pause_cancel_loop; - -static void -pause_cancel_got_headers (SoupMessage *msg, gpointer user_data) -{ - SoupSession *session = user_data; - - soup_session_pause_message (session, msg); - g_main_loop_quit (pause_cancel_loop); -} - -static gboolean -idle_quit (gpointer loop) -{ - g_main_loop_quit (loop); - return FALSE; -} - -static void -pause_cancel_finished (SoupMessage *msg, - gboolean *finished) -{ - *finished = TRUE; - /* Quit the main loop in the next iteration, because finished is emitted - * right before the item is unqueued. - */ - g_idle_add (idle_quit, pause_cancel_loop); -} - -static gboolean -pause_cancel_timeout (gpointer user_data) -{ - gboolean *timed_out = user_data; - - *timed_out = TRUE; - g_main_loop_quit (pause_cancel_loop); - return FALSE; -} - -static void -do_pause_cancel_test (void) -{ - SoupSession *session; - SoupMessage *msg; - gboolean finished = FALSE, timed_out = FALSE; - guint timeout_id; - - g_test_bug ("745094"); - - session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); - pause_cancel_loop = g_main_loop_new (NULL, FALSE); - - timeout_id = g_timeout_add_seconds (5, pause_cancel_timeout, &timed_out); - - msg = soup_message_new_from_uri ("GET", base_uri); - g_signal_connect (msg, "got-headers", - G_CALLBACK (pause_cancel_got_headers), session); - g_signal_connect (msg, "finished", - G_CALLBACK (pause_cancel_finished), &finished); - soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); - g_main_loop_run (pause_cancel_loop); - g_assert_false (finished); - - soup_session_cancel_message (session, msg, SOUP_STATUS_CANCELLED); - g_main_loop_run (pause_cancel_loop); - g_assert_true (finished); - g_assert_false (timed_out); - - soup_test_assert_message_status (msg, SOUP_STATUS_CANCELLED); - g_object_unref (msg); - - soup_test_session_abort_unref (session); - g_main_loop_unref (pause_cancel_loop); - if (!timed_out) - g_source_remove (timeout_id); -} - int main (int argc, char **argv) { @@ -801,8 +699,6 @@ main (int argc, char **argv) g_test_add_func ("/misc/cancel-while-reading/req/delayed", do_cancel_while_reading_delayed_req_test); g_test_add_func ("/misc/cancel-while-reading/req/preemptive", do_cancel_while_reading_preemptive_req_test); g_test_add_func ("/misc/aliases", do_aliases_test); - g_test_add_func ("/misc/pause-abort", do_pause_abort_test); - g_test_add_func ("/misc/pause-cancel", do_pause_cancel_test); ret = g_test_run (); diff --git a/tests/pull-api-test.c b/tests/pull-api-test.c deleted file mode 100644 index 24c4f8e1..00000000 --- a/tests/pull-api-test.c +++ /dev/null @@ -1,256 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -#include "test-utils.h" - -static GBytes *correct_response; - -static gboolean -authenticate (SoupMessage *msg, - SoupAuth *auth, - gboolean retrying) -{ - if (!retrying) { - soup_auth_authenticate (auth, "user2", "realm2"); - - return TRUE; - } - - return FALSE; -} - -#ifdef HAVE_APACHE -static void -get_correct_response (const char *uri) -{ - SoupSession *session; - SoupMessage *msg; - - session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); - msg = soup_message_new (SOUP_METHOD_GET, uri); - correct_response = soup_test_session_send (session, msg, NULL, NULL); - if (msg->status_code != SOUP_STATUS_OK) { - g_printerr ("Could not fetch %s: %d %s\n", uri, - msg->status_code, msg->reason_phrase); - exit (1); - } - - g_object_unref (msg); - soup_test_session_abort_unref (session); -} -#endif - -/* Pull API version 1: fully-async. More like a "poke" API. Rather - * than having SoupMessage emit "got_chunk" signals whenever it wants, - * we stop it after it finishes reading the message headers, and then - * tell it when we want to hear about new chunks. - */ - -typedef struct { - GMainLoop *loop; - SoupSession *session; - SoupMessage *msg; - guint timeout; - gboolean chunks_ready; - gboolean chunk_wanted; - gboolean did_first_timeout; - gsize read_so_far; - guint expected_status; -} FullyAsyncData; - -static void fully_async_got_headers (SoupMessage *msg, gpointer user_data); -static gboolean fully_async_request_chunk (gpointer user_data); - -static void -fully_async_finished (SoupMessage *msg, - FullyAsyncData *ad) -{ - soup_test_assert_message_status (msg, ad->expected_status); - - if (ad->timeout != 0) - g_source_remove (ad->timeout); - - /* Since our test program is only running the loop for the - * purpose of this one test, we quit the loop once the - * test is done. - */ - g_main_loop_quit (ad->loop); -} - -static void -do_fully_async_test (SoupSession *session, - const char *base_uri, const char *sub_uri, - gboolean fast_request, guint expected_status) -{ - GMainLoop *loop; - FullyAsyncData ad; - SoupMessage *msg; - char *uri; - - loop = g_main_loop_new (NULL, FALSE); - - uri = g_build_filename (base_uri, sub_uri, NULL); - debug_printf (1, "GET %s\n", uri); - - msg = soup_message_new (SOUP_METHOD_GET, uri); - g_free (uri); - - ad.loop = loop; - ad.session = session; - ad.msg = msg; - ad.chunks_ready = FALSE; - ad.chunk_wanted = FALSE; - ad.did_first_timeout = FALSE; - ad.read_so_far = 0; - ad.expected_status = expected_status; - - g_signal_connect (msg, "authenticate", - G_CALLBACK (authenticate), NULL); - - /* Connect to "got_headers", from which we'll decide where to - * go next. - */ - g_signal_connect (msg, "got_headers", - G_CALLBACK (fully_async_got_headers), &ad); - - /* Send the request */ - g_signal_connect (msg, "finished", - G_CALLBACK (fully_async_finished), &ad); - soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL); - - /* In a real program, we'd probably just return at this point. - * Eventually the caller would return all the way to the main - * loop, and then eventually, some event would cause the - * application to request a chunk of data from the message - * response. - * - * In our test program, there is no "real" main loop, so we - * had to create our own. We use a timeout to represent the - * event that causes the app to decide to request another body - * chunk. We use short timeouts in one set of tests, and long - * ones in another, to test both the - * chunk-requested-before-its-been-read and - * chunk-read-before-its-been-requested cases. - */ - ad.timeout = g_timeout_add (fast_request ? 0 : 100, - fully_async_request_chunk, &ad); - g_main_loop_run (ad.loop); - g_main_loop_unref (ad.loop); -} - -static gboolean -fully_async_request_chunk (gpointer user_data) -{ - FullyAsyncData *ad = user_data; - - if (!ad->did_first_timeout) { - debug_printf (1, " first timeout\n"); - ad->did_first_timeout = TRUE; - } else - debug_printf (2, " timeout\n"); - ad->timeout = 0; - - /* ad->chunks_ready and ad->chunk_wanted are used because - * there's a race condition between the application requesting - * the first chunk, and the message reaching a point where - * it's actually ready to read chunks. If chunks_ready has - * been set, we can just call soup_session_unpause_message() to - * cause the first chunk to be read. But if it's not, we just - * set chunk_wanted, to let the got_headers handler below know - * that a chunk has already been requested. - */ - if (ad->chunks_ready) - soup_session_unpause_message (ad->session, ad->msg); - else - ad->chunk_wanted = TRUE; - - return FALSE; -} - -static void -fully_async_got_headers (SoupMessage *msg, gpointer user_data) -{ - FullyAsyncData *ad = user_data; - - debug_printf (1, " %d %s\n", msg->status_code, msg->reason_phrase); - if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) { - /* Let soup handle this one; this got_headers handler - * will get called again next time around. - */ - return; - } else if (msg->status_code != SOUP_STATUS_OK) { - soup_test_assert_message_status (msg, SOUP_STATUS_OK); - return; - } - - /* OK, we're happy with the response. So, we connect to - * "got_chunk". If there has already been a chunk requested, - * we let I/O continue; but if there hasn't, we pause now - * until one is requested. - */ - ad->chunks_ready = TRUE; - if (!ad->chunk_wanted) - soup_session_pause_message (ad->session, msg); -} - -static void -do_fast_async_test (gconstpointer data) -{ - const char *base_uri = data; - SoupSession *session; - - SOUP_TEST_SKIP_IF_NO_APACHE; - - session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); - do_fully_async_test (session, base_uri, "/", - TRUE, SOUP_STATUS_OK); - do_fully_async_test (session, base_uri, "/Basic/realm1/", - TRUE, SOUP_STATUS_UNAUTHORIZED); - do_fully_async_test (session, base_uri, "/Basic/realm2/", - TRUE, SOUP_STATUS_OK); - soup_test_session_abort_unref (session); -} - -static void -do_slow_async_test (gconstpointer data) -{ - const char *base_uri = data; - SoupSession *session; - - SOUP_TEST_SKIP_IF_NO_APACHE; - - session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); - do_fully_async_test (session, base_uri, "/", - FALSE, SOUP_STATUS_OK); - do_fully_async_test (session, base_uri, "/Basic/realm1/", - FALSE, SOUP_STATUS_UNAUTHORIZED); - do_fully_async_test (session, base_uri, "/Basic/realm2/", - FALSE, SOUP_STATUS_OK); - soup_test_session_abort_unref (session); -} - -int -main (int argc, char **argv) -{ - const char *base_uri; - int ret; - - test_init (argc, argv, NULL); - apache_init (); - - base_uri = "http://127.0.0.1:47524/"; -#ifdef HAVE_APACHE - get_correct_response (base_uri); -#endif - - g_test_add_data_func ("/pull-api/async/fast", base_uri, do_fast_async_test); - g_test_add_data_func ("/pull-api/async/slow", base_uri, do_slow_async_test); - - ret = g_test_run (); - -#ifdef HAVE_APACHE - g_bytes_unref (correct_response); -#endif - - test_cleanup (); - return ret; -} diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c index 19fc850d..03cfd874 100644 --- a/tests/sniffing-test.c +++ b/tests/sniffing-test.c @@ -7,7 +7,6 @@ SoupSession *session; SoupURI *base_uri; -SoupMessageBody *chunk_data; static void server_callback (SoupServer *server, @@ -137,74 +136,32 @@ server_callback (SoupServer *server, soup_message_body_complete (response_body); } -static gboolean -unpause_msg (gpointer data) -{ - SoupMessage *msg = (SoupMessage*)data; - debug_printf (2, " unpause\n"); - soup_session_unpause_message (session, msg); - return FALSE; -} - - static void -content_sniffed (SoupMessage *msg, char *content_type, GHashTable *params, gpointer data) +content_sniffed (SoupMessage *msg, + char *content_type, + GHashTable *params) { - gboolean should_pause = GPOINTER_TO_INT (data); - debug_printf (2, " content-sniffed -> %s\n", content_type); soup_test_assert (g_object_get_data (G_OBJECT (msg), "got-chunk") == NULL, "got-chunk got emitted before content-sniffed"); g_object_set_data (G_OBJECT (msg), "content-sniffed", GINT_TO_POINTER (TRUE)); - - if (should_pause) { - debug_printf (2, " pause\n"); - soup_session_pause_message (session, msg); - g_idle_add (unpause_msg, msg); - } } static void -got_headers (SoupMessage *msg, gpointer data) +got_headers (SoupMessage *msg) { - gboolean should_pause = GPOINTER_TO_INT (data); - debug_printf (2, " got-headers\n"); soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") == NULL, "content-sniffed got emitted before got-headers"); g_object_set_data (G_OBJECT (msg), "got-headers", GINT_TO_POINTER (TRUE)); - - if (should_pause) { - debug_printf (2, " pause\n"); - soup_session_pause_message (session, msg); - g_idle_add (unpause_msg, msg); - } -} - -static void -got_chunk (SoupMessage *msg, GBytes *chunk, gpointer data) -{ - gboolean should_accumulate = GPOINTER_TO_INT (data); - - debug_printf (2, " got-chunk\n"); - - g_object_set_data (G_OBJECT (msg), "got-chunk", GINT_TO_POINTER (TRUE)); - - if (!should_accumulate) { - if (!chunk_data) - chunk_data = soup_message_body_new (); - soup_message_body_append_bytes (chunk_data, chunk); - } } static void do_signals_test (gboolean should_content_sniff, - gboolean should_pause, - gboolean should_accumulate, gboolean chunked_encoding, gboolean empty_response) { @@ -214,10 +171,8 @@ do_signals_test (gboolean should_content_sniff, GError *error = NULL; GBytes *body = NULL; - debug_printf (1, "do_signals_test(%ssniff, %spause, %saccumulate, %schunked, %sempty)\n", + debug_printf (1, "do_signals_test(%ssniff, %schunked, %sempty)\n", should_content_sniff ? "" : "!", - should_pause ? "" : "!", - should_accumulate ? "" : "!", chunked_encoding ? "" : "!", empty_response ? "" : "!"); @@ -235,19 +190,12 @@ do_signals_test (gboolean should_content_sniff, soup_message_set_uri (msg, uri); -#if 0 - soup_message_body_set_accumulate (msg->response_body, should_accumulate); -#endif - g_object_connect (msg, - "signal::got-headers", got_headers, GINT_TO_POINTER (should_pause), - "signal::got-chunk", got_chunk, GINT_TO_POINTER (should_accumulate), - "signal::content_sniffed", content_sniffed, GINT_TO_POINTER (should_pause), + "signal::got-headers", got_headers, NULL, + "signal::content_sniffed", content_sniffed, NULL, NULL); -#if 0 - soup_test_session_async_send_message (session, msg); -#endif + body = soup_test_session_async_send (session, msg); if (should_content_sniff) { soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") != NULL, @@ -264,13 +212,6 @@ do_signals_test (gboolean should_content_sniff, g_assert_no_error (error); } - if (!should_accumulate && chunk_data) - body = soup_message_body_flatten (chunk_data); -#if 0 - else if (msg->response_body) - body = soup_message_body_flatten (msg->response_body); -#endif - if (body) { //g_message ("|||body (%zu): %s", g_bytes_get_size (body), (char*)g_bytes_get_data (body, NULL)); //g_message ("|||expected (%zu): %s", g_bytes_get_size (expected), (char*)g_bytes_get_data (expected, NULL)); @@ -279,7 +220,6 @@ do_signals_test (gboolean should_content_sniff, g_bytes_unref (expected); g_bytes_unref (body); - g_clear_pointer (&chunk_data, soup_message_body_free); soup_uri_free (uri); g_object_unref (msg); } @@ -289,35 +229,17 @@ do_signals_tests (gconstpointer data) { gboolean should_content_sniff = GPOINTER_TO_INT (data); - g_test_skip ("FIXME"); - return; - if (!should_content_sniff) soup_session_remove_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER); do_signals_test (should_content_sniff, - FALSE, FALSE, FALSE, FALSE); - do_signals_test (should_content_sniff, - FALSE, FALSE, TRUE, FALSE); + FALSE, FALSE); do_signals_test (should_content_sniff, - FALSE, TRUE, FALSE, FALSE); - do_signals_test (should_content_sniff, - FALSE, TRUE, TRUE, FALSE); - - do_signals_test (should_content_sniff, - TRUE, TRUE, FALSE, FALSE); - do_signals_test (should_content_sniff, - TRUE, TRUE, TRUE, FALSE); - do_signals_test (should_content_sniff, - TRUE, FALSE, FALSE, FALSE); - do_signals_test (should_content_sniff, - TRUE, FALSE, TRUE, FALSE); - - /* FIXME g_test_bug ("587907") */ + TRUE, FALSE); do_signals_test (should_content_sniff, - TRUE, TRUE, FALSE, TRUE); + FALSE, TRUE); do_signals_test (should_content_sniff, - TRUE, TRUE, TRUE, TRUE); + TRUE, TRUE); if (!should_content_sniff) soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER); |
