summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gmail.com>2020-10-27 12:09:21 +0000
committerEmmanuele Bassi <ebassi@gmail.com>2020-10-27 12:09:21 +0000
commitcfbab734d1187617dffc855689abf5566a8883ee (patch)
treee76420316bdb7bf88a4ed0bcdd28b301aa6bbccb
parent614d40941b27ca11cda4473511911aa1888b3ee1 (diff)
parent832d09ad4b0e162a3b1157598eed24b81c007156 (diff)
Merge branch 'backport-1711-socket-fix-glib-2-66' into 'glib-2-66'
Backport !1711 “Fix race in socketclient-slow test” to glib-2-66 See merge request GNOME/glib!1723
-rw-r--r--gio/tests/gsocketclient-slow.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/gio/tests/gsocketclient-slow.c b/gio/tests/gsocketclient-slow.c
index 34410f4cf..803ed9082 100644
--- a/gio/tests/gsocketclient-slow.c
+++ b/gio/tests/gsocketclient-slow.c
@@ -79,23 +79,26 @@ on_connected_cancelled (GObject *source_object,
g_main_loop_quit (user_data);
}
-static int
-on_timer (GCancellable *cancel)
+typedef struct
{
- g_cancellable_cancel (cancel);
- return G_SOURCE_REMOVE;
-}
+ GCancellable *cancellable;
+ gboolean completed;
+} EventCallbackData;
static void
on_event (GSocketClient *client,
GSocketClientEvent event,
GSocketConnectable *connectable,
GIOStream *connection,
- gboolean *got_completed_event)
+ EventCallbackData *data)
{
- if (event == G_SOCKET_CLIENT_COMPLETE)
+ if (data->cancellable && event == G_SOCKET_CLIENT_CONNECTED)
+ {
+ g_cancellable_cancel (data->cancellable);
+ }
+ else if (event == G_SOCKET_CLIENT_COMPLETE)
{
- *got_completed_event = TRUE;
+ data->completed = TRUE;
g_assert_null (connection);
}
}
@@ -108,8 +111,7 @@ test_happy_eyeballs_cancel_delayed (void)
GError *error = NULL;
guint16 port;
GMainLoop *loop;
- GCancellable *cancel;
- gboolean got_completed_event = FALSE;
+ EventCallbackData data = { NULL, FALSE };
/* This just tests that cancellation works as expected, still emits the completed signal,
* and never returns a connection */
@@ -122,17 +124,16 @@ test_happy_eyeballs_cancel_delayed (void)
g_socket_service_start (service);
client = g_socket_client_new ();
- cancel = g_cancellable_new ();
- g_socket_client_connect_to_host_async (client, "localhost", port, cancel, on_connected_cancelled, loop);
- g_timeout_add (1, (GSourceFunc) on_timer, cancel);
- g_signal_connect (client, "event", G_CALLBACK (on_event), &got_completed_event);
+ data.cancellable = g_cancellable_new ();
+ g_socket_client_connect_to_host_async (client, "localhost", port, data.cancellable, on_connected_cancelled, loop);
+ g_signal_connect (client, "event", G_CALLBACK (on_event), &data);
g_main_loop_run (loop);
- g_assert_true (got_completed_event);
+ g_assert_true (data.completed);
g_main_loop_unref (loop);
g_object_unref (service);
g_object_unref (client);
- g_object_unref (cancel);
+ g_object_unref (data.cancellable);
}
static void
@@ -144,7 +145,7 @@ test_happy_eyeballs_cancel_instant (void)
guint16 port;
GMainLoop *loop;
GCancellable *cancel;
- gboolean got_completed_event = FALSE;
+ EventCallbackData data = { NULL, FALSE };
/* This tests the same things as above, test_happy_eyeballs_cancel_delayed(), but
* with different timing since it sends an already cancelled cancellable */
@@ -160,10 +161,10 @@ test_happy_eyeballs_cancel_instant (void)
cancel = g_cancellable_new ();
g_cancellable_cancel (cancel);
g_socket_client_connect_to_host_async (client, "localhost", port, cancel, on_connected_cancelled, loop);
- g_signal_connect (client, "event", G_CALLBACK (on_event), &got_completed_event);
+ g_signal_connect (client, "event", G_CALLBACK (on_event), &data);
g_main_loop_run (loop);
- g_assert_true (got_completed_event);
+ g_assert_true (data.completed);
g_main_loop_unref (loop);
g_object_unref (service);
g_object_unref (client);