[gnome-software/wip/mcrha/plugin-loader-self-test] gs-plugin-loader: Flag and use special plugin loader for the self tests



commit 7bf295e6dea909e38220104246127c67d41aaa79
Author: Milan Crha <mcrha redhat com>
Date:   Wed Oct 6 15:41:30 2021 +0200

    gs-plugin-loader: Flag and use special plugin loader for the self tests
    
    This way it's possible to recognize and avoid unnecessary work during
    the self tests. One such thing is the ODRS download on each refresh,
    which can slow down the tests significantly.

 lib/gs-plugin-loader.c                  | 39 ++++++++++++++++++++++++++++++++-
 lib/gs-plugin-loader.h                  |  2 ++
 plugins/core/gs-self-test.c             |  2 +-
 plugins/dpkg/gs-self-test.c             |  2 +-
 plugins/dummy/gs-self-test.c            |  2 +-
 plugins/fedora-langpacks/gs-self-test.c |  2 +-
 plugins/flatpak/gs-self-test.c          |  2 +-
 plugins/fwupd/gs-self-test.c            |  2 +-
 plugins/modalias/gs-self-test.c         |  2 +-
 plugins/packagekit/gs-self-test.c       |  2 +-
 plugins/repos/gs-self-test.c            |  2 +-
 plugins/snap/gs-self-test.c             |  2 +-
 12 files changed, 50 insertions(+), 11 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 7f5859a05..2b3b9185d 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -78,6 +78,8 @@ struct _GsPluginLoader
 #ifdef HAVE_SYSPROF
        SysprofCaptureWriter    *sysprof_writer;  /* (owned) (nullable) */
 #endif
+
+       gboolean                 self_test;
 };
 
 static void gs_plugin_loader_monitor_network (GsPluginLoader *plugin_loader);
@@ -1235,7 +1237,8 @@ gs_plugin_loader_run_results (GsPluginLoaderHelper *helper,
        }
 
        if (action == GS_PLUGIN_ACTION_REFRESH &&
-           plugin_loader->odrs_provider != NULL) {
+           plugin_loader->odrs_provider != NULL &&
+           !gs_plugin_loader_is_self_test (plugin_loader)) {
                /* FIXME: Using plugin_loader->plugins->pdata[0] is a hack; the
                 * GsOdrsProvider needs access to a GsPlugin to access global
                 * state for gs_plugin_download_file(), but it doesn’t really
@@ -3096,6 +3099,40 @@ gs_plugin_loader_new (void)
        return GS_PLUGIN_LOADER (plugin_loader);
 }
 
+/**
+ * gs_plugin_loader_new_self_test:
+ *
+ * Creates a new #GsPluginLoader, which is used inside a self test. That can
+ * be checked with gs_plugin_loader_is_self_test().
+ *
+ * Returns: (transfer full): a new #GsPluginLoader for the self test.
+ *
+ * Since: 42
+ **/
+GsPluginLoader *
+gs_plugin_loader_new_self_test (void)
+{
+       GsPluginLoader *plugin_loader;
+       plugin_loader = g_object_new (GS_TYPE_PLUGIN_LOADER, NULL);
+       plugin_loader->self_test = TRUE;
+       return plugin_loader;
+}
+
+/**
+ * gs_plugin_loader_is_self_test:
+ * @plugin_loader: a #GsPluginLoader
+ *
+ * Returns: Whether the @plugin_loader had been created for a self test.
+ *
+ * Since: 42
+ **/
+gboolean
+gs_plugin_loader_is_self_test (GsPluginLoader *plugin_loader)
+{
+       g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), FALSE);
+       return plugin_loader->self_test;
+}
+
 static void
 gs_plugin_loader_app_installed_cb (GObject *source,
                                   GAsyncResult *res,
diff --git a/lib/gs-plugin-loader.h b/lib/gs-plugin-loader.h
index 71fd35af8..4fabd883c 100644
--- a/lib/gs-plugin-loader.h
+++ b/lib/gs-plugin-loader.h
@@ -25,6 +25,8 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GsPluginLoader, gs_plugin_loader, GS, PLUGIN_LOADER, GObject)
 
 GsPluginLoader *gs_plugin_loader_new                   (void);
+GsPluginLoader *gs_plugin_loader_new_self_test         (void);
+gboolean        gs_plugin_loader_is_self_test          (GsPluginLoader *plugin_loader);
 void            gs_plugin_loader_job_process_async     (GsPluginLoader *plugin_loader,
                                                         GsPluginJob    *plugin_job,
                                                         GCancellable   *cancellable,
diff --git a/plugins/core/gs-self-test.c b/plugins/core/gs-self-test.c
index 16894b915..2edcff672 100644
--- a/plugins/core/gs-self-test.c
+++ b/plugins/core/gs-self-test.c
@@ -255,7 +255,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        ret = gs_plugin_loader_setup (plugin_loader,
                                      (gchar**) allowlist,
diff --git a/plugins/dpkg/gs-self-test.c b/plugins/dpkg/gs-self-test.c
index e3a76b230..54ee18bb2 100644
--- a/plugins/dpkg/gs-self-test.c
+++ b/plugins/dpkg/gs-self-test.c
@@ -78,7 +78,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        ret = gs_plugin_loader_setup (plugin_loader,
                                      (gchar**) allowlist,
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 8d80f08d2..0816e49dd 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -829,7 +829,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        g_signal_connect (plugin_loader, "status-changed",
                          G_CALLBACK (gs_plugin_loader_status_changed_cb), NULL);
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
diff --git a/plugins/fedora-langpacks/gs-self-test.c b/plugins/fedora-langpacks/gs-self-test.c
index 895f2f8b0..980707404 100644
--- a/plugins/fedora-langpacks/gs-self-test.c
+++ b/plugins/fedora-langpacks/gs-self-test.c
@@ -78,7 +78,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        ret = gs_plugin_loader_setup (plugin_loader,
                                      (gchar**) allowlist,
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index 2789d4f70..3fff0567b 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -1944,7 +1944,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR_CORE);
        ret = gs_plugin_loader_setup (plugin_loader,
diff --git a/plugins/fwupd/gs-self-test.c b/plugins/fwupd/gs-self-test.c
index 2c0bf10b2..c21c5684e 100644
--- a/plugins/fwupd/gs-self-test.c
+++ b/plugins/fwupd/gs-self-test.c
@@ -86,7 +86,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        ret = gs_plugin_loader_setup (plugin_loader,
                                      (gchar**) allowlist,
diff --git a/plugins/modalias/gs-self-test.c b/plugins/modalias/gs-self-test.c
index 92bf88f00..4b18f6735 100644
--- a/plugins/modalias/gs-self-test.c
+++ b/plugins/modalias/gs-self-test.c
@@ -90,7 +90,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR_CORE);
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR_DUMMY);
diff --git a/plugins/packagekit/gs-self-test.c b/plugins/packagekit/gs-self-test.c
index 4a9cff58e..0872ea8eb 100644
--- a/plugins/packagekit/gs-self-test.c
+++ b/plugins/packagekit/gs-self-test.c
@@ -262,7 +262,7 @@ main (int argc, char **argv)
        g_test_add_func ("/gnome-software/markdown", gs_markdown_func);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        ret = gs_plugin_loader_setup (plugin_loader,
                                      (gchar**) allowlist,
diff --git a/plugins/repos/gs-self-test.c b/plugins/repos/gs-self-test.c
index ff5b3e726..3fde747bf 100644
--- a/plugins/repos/gs-self-test.c
+++ b/plugins/repos/gs-self-test.c
@@ -63,7 +63,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        ret = gs_plugin_loader_setup (plugin_loader,
                                      (gchar**) allowlist,
diff --git a/plugins/snap/gs-self-test.c b/plugins/snap/gs-self-test.c
index 621f6f8f5..d81e4eb0a 100644
--- a/plugins/snap/gs-self-test.c
+++ b/plugins/snap/gs-self-test.c
@@ -365,7 +365,7 @@ main (int argc, char **argv)
        g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
 
        /* we can only load this once per process */
-       plugin_loader = gs_plugin_loader_new ();
+       plugin_loader = gs_plugin_loader_new_self_test ();
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
        gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR_CORE);
        ret = gs_plugin_loader_setup (plugin_loader,


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