summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2015-03-17 15:53:36 +0100
committerChristophe Fergeau <cfergeau@redhat.com>2015-03-17 15:58:26 +0100
commit08f1fc35e3c77aecedacf08aa510e82c91ac7f2a (patch)
treee25b8cb78388ad7ba2ae3f6d8ceff5112c6f6e79
parentb993cab540e19e6fa8a488b520f7ef7dc2602b2f (diff)
downloadlibrest-08f1fc35e3c77aecedacf08aa510e82c91ac7f2a.tar.gz
tests: Avoid race condition in threaded tests0.7.93
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.
-rw-r--r--tests/custom-serialize.c4
-rw-r--r--tests/threaded.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/tests/custom-serialize.c b/tests/custom-serialize.c
index f683941..c4ca541 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 ecb074f..abb11e7 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)