tests: Add a missing poll condition to socket-listener test

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 <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2025-07-31 00:11:25 +01:00
parent 364f33c168
commit 2326db507d

View File

@@ -573,19 +573,31 @@ any_are_null (const void * const *ptr_array,
return FALSE; return FALSE;
} }
static void typedef struct
test_accept_multi_simultaneously (void)
{
GSocketListener *listener = NULL;
GAsyncResult *accept_results[5] = { NULL, };
struct
{ {
uint16_t listening_port; uint16_t listening_port;
GSocketClient *client; GSocketClient *client;
GAsyncResult *result; GAsyncResult *result;
GSocketConnection *connection; 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;
} }
clients[5] = { { 0, NULL, NULL, NULL }, };
static void
test_accept_multi_simultaneously (void)
{
GSocketListener *listener = NULL;
GAsyncResult *accept_results[5] = { NULL, };
AcceptMultiSimultaneouslyClient clients[5] = { { 0, NULL, NULL, NULL }, };
GSocketConnection *server_connection = NULL; GSocketConnection *server_connection = NULL;
GCancellable *cancellable = NULL; GCancellable *cancellable = NULL;
GError *local_error = NULL; GError *local_error = NULL;
@@ -620,7 +632,8 @@ test_accept_multi_simultaneously (void)
cancellable, async_result_cb, &clients[i].result); 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); g_main_context_iteration (NULL, TRUE);
/* Exactly one server connection should have been created, because we called /* Exactly one server connection should have been created, because we called