[glib: 1/2] tests/desktop-app-info: Use unique temporary paths for action files




commit 02de2350592141b0165001b8c87b8075c977f0aa
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Sep 13 02:44:25 2022 +0200

    tests/desktop-app-info: Use unique temporary paths for action files
    
    desktop-app-info test may fail when repeated with multiple concurrent
    processes because the actions test relies on checking the existence of
    in the shared build directory, so by doing something like:
    
      meson test -C _build desktop-app-info -t 0.3 --repeat 80
    
    We may end up in timeout errors, because we are waiting for files that
    have been already deleted by other processes.
    
    To avoid this, let's rely on writing the files on `$G_TEST_TMPDIR` env
    variable, that is always set and unique, given that we're using the
    G_TEST_OPTION_ISOLATE_DIRS test option.

 gio/tests/appinfo-test-actions.desktop |  6 +++---
 gio/tests/desktop-app-info.c           | 23 +++++++++++++++++++----
 2 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/gio/tests/appinfo-test-actions.desktop b/gio/tests/appinfo-test-actions.desktop
index 86e3bcfc09..65f3216a91 100644
--- a/gio/tests/appinfo-test-actions.desktop
+++ b/gio/tests/appinfo-test-actions.desktop
@@ -5,12 +5,12 @@ Exec=true
 
 [Desktop Action frob]
 Name=Frobnicate
-Exec=touch frob
+Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/frob"'
 
 [Desktop Action tweak]
 Name=Tweak
-Exec=touch tweak
+Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/tweak"'
 
 [Desktop Action twiddle]
 Name=Twiddle
-Exec=touch twiddle
+Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/twiddle"'
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index 6d3f4e853c..87bf39dc71 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -551,7 +551,11 @@ test_actions (void)
   const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL };
   const gchar * const *actions;
   GDesktopAppInfo *appinfo;
+  const gchar *tmpdir;
   gchar *name;
+  gchar *frob_path;
+  gchar *tweak_path;
+  gchar *twiddle_path;
 
   appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, 
"appinfo-test-actions.desktop", NULL));
   g_assert_nonnull (appinfo);
@@ -576,17 +580,28 @@ test_actions (void)
   g_assert_true (g_utf8_validate (name, -1, NULL));
   g_free (name);
 
-  unlink ("frob"); unlink ("tweak"); unlink ("twiddle");
+  tmpdir = g_getenv ("G_TEST_TMPDIR");
+  g_assert_nonnull (tmpdir);
+  frob_path = g_build_filename (tmpdir, "frob", NULL);
+  tweak_path = g_build_filename (tmpdir, "tweak", NULL);
+  twiddle_path = g_build_filename (tmpdir, "twiddle", NULL);
+
+  g_assert_false (g_file_test (frob_path, G_FILE_TEST_EXISTS));
+  g_assert_false (g_file_test (tweak_path, G_FILE_TEST_EXISTS));
+  g_assert_false (g_file_test (twiddle_path, G_FILE_TEST_EXISTS));
 
   g_desktop_app_info_launch_action (appinfo, "frob", NULL);
-  wait_for_file ("frob", "tweak", "twiddle");
+  wait_for_file (frob_path, tweak_path, twiddle_path);
 
   g_desktop_app_info_launch_action (appinfo, "tweak", NULL);
-  wait_for_file ("tweak", "frob", "twiddle");
+  wait_for_file (tweak_path, frob_path, twiddle_path);
 
   g_desktop_app_info_launch_action (appinfo, "twiddle", NULL);
-  wait_for_file ("twiddle", "frob", "tweak");
+  wait_for_file (twiddle_path, frob_path, tweak_path);
 
+  g_free (frob_path);
+  g_free (tweak_path);
+  g_free (twiddle_path);
   g_object_unref (appinfo);
 }
 


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