[gnome-software/skip-saving-install-queue] Save install queue in separate dir for each unit test
- From: Phaedrus Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/skip-saving-install-queue] Save install queue in separate dir for each unit test
- Date: Fri, 14 Aug 2020 20:54:32 +0000 (UTC)
commit 9a7ca4f5d0dd9ee6a7d6905acccd927ee9ce1cb0
Author: Phaedrus Leeds <matthew leeds endlessm com>
Date: Thu Aug 13 12:23:58 2020 -0700
Save install queue in separate dir for each unit test
Currently some unit tests fail with a message like:
Bail out! Gs-FATAL-WARNING: failed to create an app for */*/*/*/chiron.desktop/*
This is because the tests are being run in parallel, and in
gs_plugin_loader_setup() we load the install queue from the disk, but
the queue is also being written to by other tests so it may have apps in
it which can't be understood by the plugin being tested (chiron.desktop
is only used by the dummy plugin).
So, read and write the install queue from a temporary directory that is
unique to each self test, using an env var set only by those tests. One
might wonder if we could instead use G_TEST_OPTION_ISOLATE_DIRS, but
that only takes effect during g_test_run() and we call
gs_plugin_loader_setup() before that. Another option would be a
gs_plugin_loader_override_install_dir() function but using an env var is
more consistent with how we do similar overrides, e.g.
GS_SELF_TEST_CACHEDIR.
lib/gs-plugin-loader.c | 8 ++++++--
plugins/core/gs-self-test.c | 1 +
plugins/dpkg/gs-self-test.c | 5 +++++
plugins/dummy/gs-self-test.c | 1 +
plugins/fedora-langpacks/gs-self-test.c | 5 +++++
plugins/flatpak/gs-self-test.c | 1 +
plugins/fwupd/gs-self-test.c | 5 +++++
plugins/modalias/gs-self-test.c | 1 +
plugins/packagekit/gs-self-test.c | 5 +++++
plugins/repos/gs-self-test.c | 5 +++++
plugins/snap/gs-self-test.c | 5 +++++
11 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 7783f778..7e99dd66 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1752,9 +1752,11 @@ load_install_queue (GsPluginLoader *plugin_loader, GError **error)
g_autofree gchar *file = NULL;
g_auto(GStrv) names = NULL;
g_autoptr(GsAppList) list = NULL;
+ const gchar *tmp_data_dir;
/* load from file */
- file = g_build_filename (g_get_user_data_dir (),
+ tmp_data_dir = g_getenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR");
+ file = g_build_filename (tmp_data_dir != NULL ? tmp_data_dir : g_get_user_data_dir (),
"gnome-software",
"install-queue",
NULL);
@@ -1807,6 +1809,7 @@ save_install_queue (GsPluginLoader *plugin_loader)
g_autoptr(GError) error = NULL;
g_autoptr(GString) s = NULL;
g_autofree gchar *file = NULL;
+ const gchar *tmp_data_dir;
s = g_string_new ("");
pending_apps = priv->pending_apps;
@@ -1822,7 +1825,8 @@ save_install_queue (GsPluginLoader *plugin_loader)
g_mutex_unlock (&priv->pending_apps_mutex);
/* save file */
- file = g_build_filename (g_get_user_data_dir (),
+ tmp_data_dir = g_getenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR");
+ file = g_build_filename (tmp_data_dir != NULL ? tmp_data_dir : g_get_user_data_dir (),
"gnome-software",
"install-queue",
NULL);
diff --git a/plugins/core/gs-self-test.c b/plugins/core/gs-self-test.c
index 5aabbdfd..5c112861 100644
--- a/plugins/core/gs-self-test.c
+++ b/plugins/core/gs-self-test.c
@@ -217,6 +217,7 @@ main (int argc, char **argv)
tmp_root = g_dir_make_tmp ("gnome-software-core-test-XXXXXX", NULL);
g_assert (tmp_root != NULL);
g_setenv ("GS_SELF_TEST_CACHEDIR", tmp_root, TRUE);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
os_release_filename = gs_test_get_filename (TESTDATADIR, "os-release");
g_assert (os_release_filename != NULL);
diff --git a/plugins/dpkg/gs-self-test.c b/plugins/dpkg/gs-self-test.c
index e3a76b23..e63c30c3 100644
--- a/plugins/dpkg/gs-self-test.c
+++ b/plugins/dpkg/gs-self-test.c
@@ -52,6 +52,7 @@ gs_plugins_dpkg_func (GsPluginLoader *plugin_loader)
int
main (int argc, char **argv)
{
+ g_autofree gchar *tmp_root = NULL;
gboolean ret;
g_autoptr(GError) error = NULL;
g_autoptr(GsPluginLoader) plugin_loader = NULL;
@@ -74,6 +75,10 @@ main (int argc, char **argv)
NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+ tmp_root = g_dir_make_tmp ("gnome-software-dpkg-test-XXXXXX", NULL);
+ g_assert_true (tmp_root != NULL);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
+
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
diff --git a/plugins/dummy/gs-self-test.c b/plugins/dummy/gs-self-test.c
index 30360ccd..1d4584e5 100644
--- a/plugins/dummy/gs-self-test.c
+++ b/plugins/dummy/gs-self-test.c
@@ -765,6 +765,7 @@ main (int argc, char **argv)
tmp_root = g_dir_make_tmp ("gnome-software-dummy-test-XXXXXX", NULL);
g_assert (tmp_root != NULL);
g_setenv ("GS_SELF_TEST_CACHEDIR", tmp_root, TRUE);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
xml = g_strdup ("<?xml version=\"1.0\"?>\n"
"<components version=\"0.9\">\n"
diff --git a/plugins/fedora-langpacks/gs-self-test.c b/plugins/fedora-langpacks/gs-self-test.c
index ac8c176d..be443fde 100644
--- a/plugins/fedora-langpacks/gs-self-test.c
+++ b/plugins/fedora-langpacks/gs-self-test.c
@@ -51,6 +51,7 @@ gs_plugins_fedora_langpacks_func (GsPluginLoader *plugin_loader)
int
main (int argc, char **argv)
{
+ g_autofree gchar *tmp_root = NULL;
gboolean ret;
g_autoptr(GError) error = NULL;
g_autoptr(GsPluginLoader) plugin_loader = NULL;
@@ -66,6 +67,10 @@ main (int argc, char **argv)
NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+ tmp_root = g_dir_make_tmp ("gnome-software-fedora-langpacks-test-XXXXXX", NULL);
+ g_assert_true (tmp_root != NULL);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
+
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
diff --git a/plugins/flatpak/gs-self-test.c b/plugins/flatpak/gs-self-test.c
index ae0acda9..89fc638c 100644
--- a/plugins/flatpak/gs-self-test.c
+++ b/plugins/flatpak/gs-self-test.c
@@ -1862,6 +1862,7 @@ main (int argc, char **argv)
tmp_root = g_dir_make_tmp ("gnome-software-flatpak-test-XXXXXX", NULL);
g_assert_true (tmp_root != NULL);
g_setenv ("GS_SELF_TEST_CACHEDIR", tmp_root, TRUE);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
g_setenv ("GS_SELF_TEST_FLATPAK_DATADIR", tmp_root, TRUE);
/* allow dist'ing with no gnome-software installed */
diff --git a/plugins/fwupd/gs-self-test.c b/plugins/fwupd/gs-self-test.c
index ca5fcb8a..ad8f1e14 100644
--- a/plugins/fwupd/gs-self-test.c
+++ b/plugins/fwupd/gs-self-test.c
@@ -60,6 +60,7 @@ gs_plugins_fwupd_func (GsPluginLoader *plugin_loader)
int
main (int argc, char **argv)
{
+ g_autofree gchar *tmp_root = NULL;
gboolean ret;
g_autoptr(GError) error = NULL;
g_autoptr(GsPluginLoader) plugin_loader = NULL;
@@ -82,6 +83,10 @@ main (int argc, char **argv)
NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+ tmp_root = g_dir_make_tmp ("gnome-software-fwupd-test-XXXXXX", NULL);
+ g_assert_true (tmp_root != NULL);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
+
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
diff --git a/plugins/modalias/gs-self-test.c b/plugins/modalias/gs-self-test.c
index 5cbb39c3..30ffa0f3 100644
--- a/plugins/modalias/gs-self-test.c
+++ b/plugins/modalias/gs-self-test.c
@@ -85,6 +85,7 @@ main (int argc, char **argv)
tmp_root = g_dir_make_tmp ("gnome-software-modalias-test-XXXXXX", NULL);
g_assert (tmp_root != NULL);
g_setenv ("GS_SELF_TEST_CACHEDIR", tmp_root, TRUE);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
diff --git a/plugins/packagekit/gs-self-test.c b/plugins/packagekit/gs-self-test.c
index 5dbaf0a7..17a69626 100644
--- a/plugins/packagekit/gs-self-test.c
+++ b/plugins/packagekit/gs-self-test.c
@@ -236,6 +236,7 @@ gs_plugins_packagekit_local_func (GsPluginLoader *plugin_loader)
int
main (int argc, char **argv)
{
+ g_autofree gchar *tmp_root = NULL;
gboolean ret;
g_autoptr(GError) error = NULL;
g_autoptr(GsPluginLoader) plugin_loader = NULL;
@@ -251,6 +252,10 @@ main (int argc, char **argv)
NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+ tmp_root = g_dir_make_tmp ("gnome-software-packagekit-test-XXXXXX", NULL);
+ g_assert_true (tmp_root != NULL);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
+
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
diff --git a/plugins/repos/gs-self-test.c b/plugins/repos/gs-self-test.c
index ff5b3e72..d6240758 100644
--- a/plugins/repos/gs-self-test.c
+++ b/plugins/repos/gs-self-test.c
@@ -38,6 +38,7 @@ gs_plugins_repos_func (GsPluginLoader *plugin_loader)
int
main (int argc, char **argv)
{
+ g_autofree gchar *tmp_root = NULL;
gboolean ret;
g_autofree gchar *reposdir = NULL;
g_autoptr(GError) error = NULL;
@@ -59,6 +60,10 @@ main (int argc, char **argv)
g_assert (reposdir != NULL);
g_setenv ("GS_SELF_TEST_REPOS_DIR", reposdir, TRUE);
+ tmp_root = g_dir_make_tmp ("gnome-software-repos-test-XXXXXX", NULL);
+ g_assert_true (tmp_root != NULL);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
+
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
diff --git a/plugins/snap/gs-self-test.c b/plugins/snap/gs-self-test.c
index f10de87b..dcf05bc9 100644
--- a/plugins/snap/gs-self-test.c
+++ b/plugins/snap/gs-self-test.c
@@ -336,6 +336,7 @@ gs_plugins_snap_test_func (GsPluginLoader *plugin_loader)
int
main (int argc, char **argv)
{
+ g_autofree gchar *tmp_root = NULL;
gboolean ret;
g_autoptr(GError) error = NULL;
g_autoptr(GsPluginLoader) plugin_loader = NULL;
@@ -351,6 +352,10 @@ main (int argc, char **argv)
NULL);
g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+ tmp_root = g_dir_make_tmp ("gnome-software-snap-test-XXXXXX", NULL);
+ g_assert_true (tmp_root != NULL);
+ g_setenv ("GS_SELF_TEST_INSTALL_QUEUE_DIR", tmp_root, TRUE);
+
/* only critical and error are fatal */
g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]