Commit 4d121746 authored by Michael Catanzaro's avatar Michael Catanzaro

Merge branch '1679-socket-service-flaky' into 'master'

Resolve "socket-service test is flaky"

Closes #1679

See merge request !687
parents 86201989 07414e17
Pipeline #61619 passed with stages
in 11 minutes and 16 seconds
...@@ -67,7 +67,7 @@ gio_tests = { ...@@ -67,7 +67,7 @@ gio_tests = {
'sleepy-stream' : {}, 'sleepy-stream' : {},
'socket' : {}, 'socket' : {},
'socket-listener' : {}, 'socket-listener' : {},
'socket-service' : { 'suite': ['flaky'] }, 'socket-service' : {},
'srvtarget' : {}, 'srvtarget' : {},
'task' : {}, 'task' : {},
'vfs' : {}, 'vfs' : {},
......
...@@ -139,6 +139,12 @@ connection_cb (GThreadedSocketService *service, ...@@ -139,6 +139,12 @@ connection_cb (GThreadedSocketService *service,
GObject *source_object, GObject *source_object,
gpointer user_data) gpointer user_data)
{ {
GMainLoop *loop = user_data;
/* Since the connection attempt has come through to be handled, stop the main
* thread waiting for it; this causes the #GSocketService to be stopped. */
g_main_loop_quit (loop);
/* Block until the main thread has dropped its ref to @service, so that we /* Block until the main thread has dropped its ref to @service, so that we
* will drop the final ref from this thread. * will drop the final ref from this thread.
*/ */
...@@ -158,7 +164,6 @@ client_connected_cb (GObject *client, ...@@ -158,7 +164,6 @@ client_connected_cb (GObject *client,
GAsyncResult *result, GAsyncResult *result,
gpointer user_data) gpointer user_data)
{ {
GMainLoop *loop = user_data;
GSocketConnection *conn; GSocketConnection *conn;
GError *error = NULL; GError *error = NULL;
...@@ -166,7 +171,6 @@ client_connected_cb (GObject *client, ...@@ -166,7 +171,6 @@ client_connected_cb (GObject *client,
g_assert_no_error (error); g_assert_no_error (error);
g_object_unref (conn); g_object_unref (conn);
g_main_loop_quit (loop);
} }
static void static void
...@@ -195,9 +199,8 @@ test_threaded_712570 (void) ...@@ -195,9 +199,8 @@ test_threaded_712570 (void)
g_assert_no_error (error); g_assert_no_error (error);
g_object_unref (addr); g_object_unref (addr);
g_signal_connect (service, "run", G_CALLBACK (connection_cb), NULL);
loop = g_main_loop_new (NULL, FALSE); loop = g_main_loop_new (NULL, FALSE);
g_signal_connect (service, "run", G_CALLBACK (connection_cb), loop);
client = g_socket_client_new (); client = g_socket_client_new ();
g_socket_client_connect_async (client, g_socket_client_connect_async (client,
...@@ -222,6 +225,11 @@ test_threaded_712570 (void) ...@@ -222,6 +225,11 @@ test_threaded_712570 (void)
g_main_context_iteration (NULL, TRUE); g_main_context_iteration (NULL, TRUE);
while (G_OBJECT (service)->ref_count > 3); while (G_OBJECT (service)->ref_count > 3);
/* Wait some more iterations, as #GTask results are deferred to the next
* #GMainContext iteration, and propagation of a #GTask result takes an
* additional ref on the source object. */
g_main_context_iteration (NULL, FALSE);
/* Drop our ref, then unlock the mutex and wait for the service to be /* Drop our ref, then unlock the mutex and wait for the service to be
* finalized. (Without the fix for 712570 it would hang forever here.) * finalized. (Without the fix for 712570 it would hang forever here.)
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment