[libsoup] tests: Separate out soup_test_server_run_in_thread()



commit b8fc685cadf5b7bdcbb88fbaa703688e28573e9e
Author: Philip Chimento <philip endlessm com>
Date:   Mon Nov 18 15:47:57 2019 -0800

    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.

 tests/test-utils.c | 28 +++++++++++++++++-----------
 tests/test-utils.h |  1 +
 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]