[glib/wip/tingping/happy-eyeballs] tests: Add gsocketclient test
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/tingping/happy-eyeballs] tests: Add gsocketclient test
- Date: Fri, 16 Nov 2018 18:55:05 +0000 (UTC)
commit 0bd7ccd290f39f4a1c84a09d436a950f7b67018a
Author: Patrick Griffis <tingping tingping se>
Date: Fri Nov 16 13:54:07 2018 -0500
tests: Add gsocketclient test
gio/tests/gsocketclient.c | 69 ++++++++++++++++++++++++++++++++++++++++
gio/tests/meson.build | 21 +++++++++++-
gio/tests/slow-connect-preload.c | 37 +++++++++++++++++++++
3 files changed, 126 insertions(+), 1 deletion(-)
---
diff --git a/gio/tests/gsocketclient.c b/gio/tests/gsocketclient.c
new file mode 100644
index 000000000..2cf2954e4
--- /dev/null
+++ b/gio/tests/gsocketclient.c
@@ -0,0 +1,69 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gio/gio.h>
+
+static void
+on_connected (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GSocketConnection *conn;
+ GError *error = NULL;
+
+ conn = g_socket_client_connect_to_uri_finish (G_SOCKET_CLIENT (source_object), result, &error);
+ g_assert_no_error (error);
+
+ g_object_unref (conn);
+ g_main_loop_quit (user_data);
+}
+
+static void
+test_happy_eyeballs (void)
+{
+ GSocketClient *client;
+ GSocketService *service;
+ GError *error = NULL;
+ guint16 port;
+ GMainLoop *loop;
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ service = g_socket_service_new ();
+ port = g_socket_listener_add_any_inet_port (G_SOCKET_LISTENER (service), NULL, &error);
+ g_assert_no_error (error);
+ g_socket_service_start (service);
+
+ client = g_socket_client_new ();
+ g_socket_client_connect_to_host_async (client, "localhost", port, NULL, on_connected, loop);
+ g_main_loop_run (loop);
+
+ g_main_loop_unref (loop);
+ g_object_unref (service);
+ g_object_unref (client);
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/socket-client/happy-eyeballs", test_happy_eyeballs);
+
+ return g_test_run ();
+}
\ No newline at end of file
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index eb77d5a0a..2d3932dbd 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -134,6 +134,18 @@ if host_machine.system() != 'windows'
'unix-mounts' : {},
'unix-streams' : {},
'g-file-info-filesystem-readonly' : {},
+ 'gsocketclient' : {
+ 'depends' : [
+ shared_library('slow-connect-preload',
+ 'slow-connect-preload.c',
+ name_prefix : '',
+ dependencies: cc.find_library('dl'),
+ )
+ ],
+ 'env' : [
+ ['LD_PRELOAD', '@0@/slow-connect-preload.so'.format(meson.current_build_dir())]
+ ]
+ },
'gschema-compile' : {'install' : false},
'trash' : {},
}
@@ -494,12 +506,19 @@ foreach test_name, extra_args : gio_tests
suite = ['gio'] + extra_args.get('suite', [])
timeout = suite.contains('slow') ? test_timeout_slow : test_timeout
+ local_test_env = test_env
+
+ foreach var : extra_args.get('env', [])
+ local_test_env.append(var[0], var[1])
+ endforeach
+
test(test_name, exe,
- env : test_env,
+ env : local_test_env,
timeout : timeout,
suite : suite,
args : ['--tap'],
is_parallel : extra_args.get('is_parallel', true),
+ depends : extra_args.get('depends', []),
)
endforeach
diff --git a/gio/tests/slow-connect-preload.c b/gio/tests/slow-connect-preload.c
new file mode 100644
index 000000000..c974f3c4c
--- /dev/null
+++ b/gio/tests/slow-connect-preload.c
@@ -0,0 +1,37 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+int
+connect (int sockfd,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
+{
+ static int (*real_connect)(int, const struct sockaddr *, socklen_t);
+
+ if (real_connect == NULL)
+ real_connect = dlsym (RTLD_NEXT, "connect");
+
+ usleep (600 * 1000);
+ return real_connect (sockfd, addr, addrlen);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]