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.
This commit is contained in:
Marco Trevisan (Treviño) 2022-09-13 02:44:25 +02:00
parent 0d823aa926
commit 02de235059
2 changed files with 22 additions and 7 deletions

View File

@ -5,12 +5,12 @@ Exec=true
[Desktop Action frob] [Desktop Action frob]
Name=Frobnicate Name=Frobnicate
Exec=touch frob Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/frob"'
[Desktop Action tweak] [Desktop Action tweak]
Name=Tweak Name=Tweak
Exec=touch tweak Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/tweak"'
[Desktop Action twiddle] [Desktop Action twiddle]
Name=Twiddle Name=Twiddle
Exec=touch twiddle Exec=sh -c '[ -d "$G_TEST_TMPDIR" ] && touch "$G_TEST_TMPDIR/twiddle"'

View File

@ -551,7 +551,11 @@ test_actions (void)
const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL }; const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL };
const gchar * const *actions; const gchar * const *actions;
GDesktopAppInfo *appinfo; GDesktopAppInfo *appinfo;
const gchar *tmpdir;
gchar *name; 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)); appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL));
g_assert_nonnull (appinfo); g_assert_nonnull (appinfo);
@ -576,17 +580,28 @@ test_actions (void)
g_assert_true (g_utf8_validate (name, -1, NULL)); g_assert_true (g_utf8_validate (name, -1, NULL));
g_free (name); 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); 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); 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); 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); g_object_unref (appinfo);
} }