From 08f1fc35e3c77aecedacf08aa510e82c91ac7f2a Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Tue, 17 Mar 2015 15:53:36 +0100 Subject: [PATCH] tests: Avoid race condition in threaded tests Calling soup_server_run in a new thread, and calling soup_server_get_port() on the same SoupServer instance right after creating the thread. With recent libsoup, this sometimes causes a crash when the 2 threads try to call soup_server_ensure_listening() at the same time. Moving the call to soup_server_get_port() before the thread creation avoids this race condition. --- tests/custom-serialize.c | 4 ++-- tests/threaded.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/custom-serialize.c b/tests/custom-serialize.c index f683941d297a..c4ca5413cad1 100644 --- a/tests/custom-serialize.c +++ b/tests/custom-serialize.c @@ -123,10 +123,10 @@ main (int argc, char **argv) server = soup_server_new (NULL); soup_server_add_handler (server, NULL, server_callback, NULL, NULL); - g_thread_create ((GThreadFunc)soup_server_run, server, FALSE, NULL); - url = g_strdup_printf ("http://127.0.0.1:%d/", soup_server_get_port (server)); + g_thread_create ((GThreadFunc)soup_server_run, server, FALSE, NULL); + proxy = rest_proxy_new (url, FALSE); call = g_object_new (REST_TYPE_CUSTOM_PROXY_CALL, "proxy", proxy, NULL); diff --git a/tests/threaded.c b/tests/threaded.c index ecb074fd76c7..abb11e7a42d3 100644 --- a/tests/threaded.c +++ b/tests/threaded.c @@ -90,10 +90,10 @@ main (int argc, char **argv) server = soup_server_new (NULL); soup_server_add_handler (server, NULL, server_callback, NULL, NULL); - g_thread_create ((GThreadFunc)soup_server_run, server, FALSE, NULL); - url = g_strdup_printf ("http://127.0.0.1:%d/", soup_server_get_port (server)); + g_thread_create ((GThreadFunc)soup_server_run, server, FALSE, NULL); + for (i = 0; i < G_N_ELEMENTS (threads); i++) { threads[i] = g_thread_create (func, url, TRUE, NULL); if (verbose) -- 2.5.0