summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2019-11-18 15:47:57 -0800
committerPhilip Chimento <philip.chimento@gmail.com>2020-11-21 09:13:48 -0800
commitb8fc685cadf5b7bdcbb88fbaa703688e28573e9e (patch)
tree4220e092d6b7c2a97ae1556c21f1eb0f9e097edb
parentc5fc923e77575f70f4e7a350a867b7b1990b17f3 (diff)
downloadlibsoup-b8fc685cadf5b7bdcbb88fbaa703688e28573e9e.tar.gz
tests: Separate out soup_test_server_run_in_thread()
In order to test a SoupServer subclass in a subsequent commit, this function will be useful to run a SoupServer that has been created elsewhere, in a thread.
-rw-r--r--tests/test-utils.c28
-rw-r--r--tests/test-utils.h1
2 files changed, 18 insertions, 11 deletions
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 24053540..de6479a0 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -428,6 +428,20 @@ run_server_thread (gpointer user_data)
return NULL;
}
+void
+soup_test_server_run_in_thread (SoupServer *server)
+{
+ GThread *thread;
+
+ g_mutex_lock (&server_start_mutex);
+
+ thread = g_thread_new ("server_thread", run_server_thread, server);
+ g_cond_wait (&server_start_cond, &server_start_mutex);
+ g_mutex_unlock (&server_start_mutex);
+
+ g_object_set_data (G_OBJECT (server), "thread", thread);
+}
+
SoupServer *
soup_test_server_new (SoupTestServerOptions options)
{
@@ -457,17 +471,9 @@ soup_test_server_new (SoupTestServerOptions options)
g_object_set_data (G_OBJECT (server), "options", GUINT_TO_POINTER (options));
- if (options & SOUP_TEST_SERVER_IN_THREAD) {
- GThread *thread;
-
- g_mutex_lock (&server_start_mutex);
-
- thread = g_thread_new ("server_thread", run_server_thread, server);
- g_cond_wait (&server_start_cond, &server_start_mutex);
- g_mutex_unlock (&server_start_mutex);
-
- g_object_set_data (G_OBJECT (server), "thread", thread);
- } else if (!(options & SOUP_TEST_SERVER_NO_DEFAULT_LISTENER))
+ if (options & SOUP_TEST_SERVER_IN_THREAD)
+ soup_test_server_run_in_thread (server);
+ else if (!(options & SOUP_TEST_SERVER_NO_DEFAULT_LISTENER))
server_listen (server);
return server;
diff --git a/tests/test-utils.h b/tests/test-utils.h
index 22e5e150..7c8a43a1 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -65,6 +65,7 @@ typedef enum {
} SoupTestServerOptions;
SoupServer *soup_test_server_new (SoupTestServerOptions options);
+void soup_test_server_run_in_thread (SoupServer *server);
GUri *soup_test_server_get_uri (SoupServer *server,
const char *scheme,
const char *host);