[gnome-software: 3/14] lib: Move gs_plugin_loader_setup_again() to test utilities




commit 9b028c23a25754c762dcf61cd4649df3336217be
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Mar 1 13:04:20 2022 +0000

    lib: Move gs_plugin_loader_setup_again() to test utilities
    
    Since it’s only ever used by the tests, it doesn’t need to be in
    `GsPluginLoader` itself.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1661

 lib/gs-plugin-loader.c         | 44 ----------------------------------------
 lib/gs-plugin-loader.h         |  3 ---
 lib/gs-test.c                  | 46 ++++++++++++++++++++++++++++++++++++++++++
 lib/gs-test.h                  |  5 +++++
 plugins/core/gs-self-test.c    |  6 +++---
 plugins/dummy/gs-self-test.c   |  6 +++---
 plugins/flatpak/gs-self-test.c | 16 +++++++--------
 7 files changed, 65 insertions(+), 61 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index eecf995a2..d25c2afe4 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -2307,50 +2307,6 @@ plugin_shutdown_cb (GObject      *source_object,
        g_main_context_wakeup (data->context);
 }
 
-/**
- * gs_plugin_loader_setup_again:
- * @plugin_loader: a #GsPluginLoader
- *
- * Calls setup on each plugin. This should only be used from the self tests
- * and in a controlled way.
- */
-void
-gs_plugin_loader_setup_again (GsPluginLoader      *plugin_loader,
-                              const gchar * const *allowlist,
-                              const gchar * const *blocklist)
-{
-       g_autoptr(GError) local_error = NULL;
-#ifdef HAVE_SYSPROF
-       gint64 begin_time_nsec G_GNUC_UNUSED = SYSPROF_CAPTURE_CURRENT_TIME;
-#endif
-
-       /* Shut down */
-       gs_plugin_loader_shutdown (plugin_loader, NULL);
-
-       /* clear global cache */
-       gs_plugin_loader_clear_caches (plugin_loader);
-
-       /* remove any events */
-       gs_plugin_loader_remove_events (plugin_loader);
-
-       /* Start all the plugins setting up again in parallel. */
-       gs_plugin_loader_setup (plugin_loader, allowlist, blocklist, NULL, &local_error);
-       g_assert_no_error (local_error);
-
-#ifdef HAVE_SYSPROF
-       if (plugin_loader->sysprof_writer != NULL) {
-               sysprof_capture_writer_add_mark (plugin_loader->sysprof_writer,
-                                                begin_time_nsec,
-                                                sched_getcpu (),
-                                                getpid (),
-                                                SYSPROF_CAPTURE_CURRENT_TIME - begin_time_nsec,
-                                                "gnome-software",
-                                                "setup-again",
-                                                NULL);
-       }
-#endif  /* HAVE_SYSPROF */
-}
-
 static gint
 gs_plugin_loader_path_sort_fn (gconstpointer a, gconstpointer b)
 {
diff --git a/lib/gs-plugin-loader.h b/lib/gs-plugin-loader.h
index 383dc3415..6a956d7d5 100644
--- a/lib/gs-plugin-loader.h
+++ b/lib/gs-plugin-loader.h
@@ -95,9 +95,6 @@ GsApp         *gs_plugin_loader_get_system_app_finish (GsPluginLoader *plugin_loader,
 GsOdrsProvider *gs_plugin_loader_get_odrs_provider     (GsPluginLoader *plugin_loader);
 
 /* only useful from the self tests */
-void            gs_plugin_loader_setup_again           (GsPluginLoader *plugin_loader,
-                                                        const gchar * const *allowlist,
-                                                        const gchar * const *blocklist);
 void            gs_plugin_loader_clear_caches          (GsPluginLoader *plugin_loader);
 GsPlugin       *gs_plugin_loader_find_plugin           (GsPluginLoader *plugin_loader,
                                                         const gchar    *plugin_name);
diff --git a/lib/gs-test.c b/lib/gs-test.c
index 7abb55e91..1dbd7b8f4 100644
--- a/lib/gs-test.c
+++ b/lib/gs-test.c
@@ -97,3 +97,49 @@ gs_test_expose_icon_theme_paths (void)
        data_dirs_joined = g_string_free (g_steal_pointer (&data_dirs_str), FALSE);
        g_setenv ("GS_SELF_TEST_ICON_THEME_PATH", data_dirs_joined, TRUE);
 }
+
+/**
+ * gs_test_reinitialise_plugin_loader:
+ * @plugin_loader: a #GsPluginLoader
+ *
+ * Calls setup on each plugin. This should only be used from the self tests
+ * and in a controlled way.
+ *
+ * Since: 42
+ */
+void
+gs_test_reinitialise_plugin_loader (GsPluginLoader      *plugin_loader,
+                                    const gchar * const *allowlist,
+                                    const gchar * const *blocklist)
+{
+       g_autoptr(GError) local_error = NULL;
+#ifdef HAVE_SYSPROF
+       gint64 begin_time_nsec G_GNUC_UNUSED = SYSPROF_CAPTURE_CURRENT_TIME;
+#endif
+
+       /* Shut down */
+       gs_plugin_loader_shutdown (plugin_loader, NULL);
+
+       /* clear global cache */
+       gs_plugin_loader_clear_caches (plugin_loader);
+
+       /* remove any events */
+       gs_plugin_loader_remove_events (plugin_loader);
+
+       /* Start all the plugins setting up again in parallel. */
+       gs_plugin_loader_setup (plugin_loader, allowlist, blocklist, NULL, &local_error);
+       g_assert_no_error (local_error);
+
+#ifdef HAVE_SYSPROF
+       if (plugin_loader->sysprof_writer != NULL) {
+               sysprof_capture_writer_add_mark (plugin_loader->sysprof_writer,
+                                                begin_time_nsec,
+                                                sched_getcpu (),
+                                                getpid (),
+                                                SYSPROF_CAPTURE_CURRENT_TIME - begin_time_nsec,
+                                                "gnome-software",
+                                                "setup-again",
+                                                NULL);
+       }
+#endif  /* HAVE_SYSPROF */
+}
diff --git a/lib/gs-test.h b/lib/gs-test.h
index 2d97fb964..8114c232e 100644
--- a/lib/gs-test.h
+++ b/lib/gs-test.h
@@ -9,6 +9,7 @@
 #pragma once
 
 #include "gs-app.h"
+#include "gs-plugin-loader.h"
 
 G_BEGIN_DECLS
 
@@ -19,4 +20,8 @@ gchar *gs_test_get_filename                   (const gchar    *testdatadir,
                                                 const gchar    *filename);
 void    gs_test_expose_icon_theme_paths        (void);
 
+void    gs_test_reinitialise_plugin_loader     (GsPluginLoader         *plugin_loader,
+                                                const gchar * const    *allowlist,
+                                                const gchar * const    *blocklist);
+
 G_END_DECLS
diff --git a/plugins/core/gs-self-test.c b/plugins/core/gs-self-test.c
index e60fcbc10..b6be1699d 100644
--- a/plugins/core/gs-self-test.c
+++ b/plugins/core/gs-self-test.c
@@ -34,7 +34,7 @@ gs_plugins_core_search_repo_name_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* force this app to be installed */
        app_tmp = gs_plugin_loader_app_create (plugin_loader, "*/*/yellow/arachne.desktop/*", NULL, &error);
@@ -70,7 +70,7 @@ gs_plugins_core_os_release_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* refine system application */
        app = gs_plugin_loader_get_system_app (plugin_loader, NULL, &error);
@@ -124,7 +124,7 @@ gs_plugins_core_generic_updates_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* create a list with generic apps */
        list = gs_app_list_new ();
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 618143270..226965815 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -109,7 +109,7 @@ gs_plugins_dummy_error_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* update, which should cause an error to be emitted */
        app = gs_app_new ("chiron.desktop");
@@ -482,7 +482,7 @@ gs_plugins_dummy_hang_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* get search result based on addon keyword */
        plugin_job = gs_plugin_job_newv (GS_PLUGIN_ACTION_SEARCH,
@@ -635,7 +635,7 @@ gs_plugins_dummy_limit_parallel_ops_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* get the updates list */
        plugin_job1 = gs_plugin_job_newv (GS_PLUGIN_ACTION_GET_DISTRO_UPDATES, NULL);
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 4d11ac0be..7d792bfda 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -281,7 +281,7 @@ gs_plugins_flatpak_app_with_runtime_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -561,7 +561,7 @@ gs_plugins_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -710,7 +710,7 @@ gs_plugins_flatpak_runtime_repo_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* write a flatpakrepo file */
        testdir = gs_test_get_filename (TESTDATADIR, "only-runtime");
@@ -845,7 +845,7 @@ gs_plugins_flatpak_runtime_repo_redundant_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* write a flatpakrepo file */
        testdir = gs_test_get_filename (TESTDATADIR, "only-runtime");
@@ -1001,7 +1001,7 @@ gs_plugins_flatpak_broken_remote_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -1097,7 +1097,7 @@ flatpak_bundle_or_ref_helper (GsPluginLoader *plugin_loader,
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -1397,7 +1397,7 @@ gs_plugins_flatpak_app_update_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
@@ -1652,7 +1652,7 @@ gs_plugins_flatpak_runtime_extension_func (GsPluginLoader *plugin_loader)
 
        /* drop all caches */
        gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
-       gs_plugin_loader_setup_again (plugin_loader, allowlist, NULL);
+       gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
 
        /* no flatpak, abort */
        g_assert_true (gs_plugin_loader_get_enabled (plugin_loader, "flatpak"));


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