From 2326db507d1b34cbaae608d2e6a1acff70a0dc34 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 31 Jul 2025 00:11:25 +0100 Subject: [PATCH] tests: Add a missing poll condition to socket-listener test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s possible for the server communications to finish one main context iteration before all of the client communications, depending on how the kernel queues socket connection messages. Fixes CI failure: https://gitlab.gnome.org/GNOME/glib/-/jobs/5341950 ``` GLib-GIO:ERROR:../gio/tests/socket-listener.c:639:test_accept_multi_simultaneously: 'clients[i].result' should not be NULL not ok /socket-listener/accept/multi-simultaneously - GLib-GIO:ERROR:../gio/tests/socket-listener.c:639:test_accept_multi_simultaneously: 'clients[i].result' should not be NULL ``` Signed-off-by: Philip Withnall --- gio/tests/socket-listener.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/gio/tests/socket-listener.c b/gio/tests/socket-listener.c index e219f966b..b1b64d0a9 100644 --- a/gio/tests/socket-listener.c +++ b/gio/tests/socket-listener.c @@ -573,19 +573,31 @@ any_are_null (const void * const *ptr_array, return FALSE; } +typedef struct +{ + uint16_t listening_port; + GSocketClient *client; + GAsyncResult *result; + GSocketConnection *connection; +} AcceptMultiSimultaneouslyClient; + +static gboolean +any_client_results_are_null (const AcceptMultiSimultaneouslyClient *clients, + size_t n_clients) +{ + for (size_t i = 0; i < n_clients; i++) + if (clients[i].result == NULL) + return TRUE; + + return FALSE; +} + static void test_accept_multi_simultaneously (void) { GSocketListener *listener = NULL; GAsyncResult *accept_results[5] = { NULL, }; - struct - { - uint16_t listening_port; - GSocketClient *client; - GAsyncResult *result; - GSocketConnection *connection; - } - clients[5] = { { 0, NULL, NULL, NULL }, }; + AcceptMultiSimultaneouslyClient clients[5] = { { 0, NULL, NULL, NULL }, }; GSocketConnection *server_connection = NULL; GCancellable *cancellable = NULL; GError *local_error = NULL; @@ -620,7 +632,8 @@ test_accept_multi_simultaneously (void) cancellable, async_result_cb, &clients[i].result); } - while (accept_results[0] == NULL) + while (accept_results[0] == NULL || + any_client_results_are_null (clients, G_N_ELEMENTS (clients))) g_main_context_iteration (NULL, TRUE); /* Exactly one server connection should have been created, because we called