diff options
author | Dan Winship <danw@gnome.org> | 2015-02-28 10:16:05 -0500 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2015-02-28 10:16:05 -0500 |
commit | 21a213b4de38b507f3b0f089e94b08846c596fdd (patch) | |
tree | 9294d16e77eb5e15cbb10ca1e4689661a989c798 | |
parent | feca9b3dcc99da94167513d8a43aa56de132f6ef (diff) | |
download | libsoup-21a213b4de38b507f3b0f089e94b08846c596fdd.tar.gz |
tests: fix a sporadic hang in connection-test
https://bugzilla.gnome.org/show_bug.cgi?id=744666
-rw-r--r-- | tests/connection-test.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/tests/connection-test.c b/tests/connection-test.c index f4846c30..90233ed8 100644 --- a/tests/connection-test.c +++ b/tests/connection-test.c @@ -54,15 +54,18 @@ timeout_request_started (SoupServer *server, SoupMessage *msg, GMainContext *context = g_main_context_get_thread_default (); guint readable; + g_signal_handlers_disconnect_by_func (server, timeout_request_started, NULL); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS; sock = soup_client_context_get_socket (client); G_GNUC_END_IGNORE_DEPRECATIONS; readable = g_signal_connect (sock, "readable", G_CALLBACK (timeout_socket), NULL); + + g_mutex_unlock (&server_mutex); while (soup_socket_is_connected (sock)) g_main_context_iteration (context, TRUE); g_signal_handler_disconnect (sock, readable); - g_signal_handlers_disconnect_by_func (server, timeout_request_started, NULL); } static void @@ -80,17 +83,18 @@ setup_timeout_persistent (SoupServer *server, SoupSocket *sock) * fail (since the client is waiting for us to * return a response). This will cause it to * emit "readable" later. - * 2. Connect to the server's request-started signal. - * 3. Run an inner main loop from that signal handler - * until the socket emits "readable". (If we don't - * do this then it's possible the client's next - * request would be ready before we returned to - * the main loop, and so the signal would never be - * emitted.) + * 2. Wait for the server to finish this request and + * start reading the next one (and lock server_mutex + * to interlock with the client and ensure that it + * doesn't start writing its next request until + * that point). + * 3. Block until "readable" is emitted, meaning the + * client has written its request. * 4. Close the socket. */ soup_socket_read (sock, buf, 1, &nread, NULL, NULL); + g_mutex_lock (&server_mutex); g_signal_connect (server, "request-started", G_CALLBACK (timeout_request_started), NULL); } @@ -256,6 +260,12 @@ do_timeout_test_for_session (SoupSession *session) } g_object_unref (msg); + /* The server will grab server_mutex before returning the response, + * and release it when it's ready for us to send the second request. + */ + g_mutex_lock (&server_mutex); + g_mutex_unlock (&server_mutex); + debug_printf (1, " Second message\n"); msg = soup_message_new_from_uri ("GET", base_uri); soup_session_send_message (session, msg); @@ -320,6 +330,12 @@ do_timeout_req_test_for_session (SoupSession *session) } g_object_unref (req); + /* The server will grab server_mutex before returning the response, + * and release it when it's ready for us to send the second request. + */ + g_mutex_lock (&server_mutex); + g_mutex_unlock (&server_mutex); + debug_printf (1, " Second request\n"); req = soup_session_request_uri (session, base_uri, NULL); |