[glib: 1/2] tests: Fix minor race in desktop-app-info terminals test




commit 1c42e2da25fc6147fa98672596b56d8731eb2c63
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Oct 17 17:40:53 2022 +0100

    tests: Fix minor race in desktop-app-info terminals test
    
    The implementation of `g_desktop_app_info_launch_uris()` will spawn the
    exec file once for each URI unless the desktop file has a placeholder in
    its Exec line which supports multiple URIs at once.
    
    The fake terminal doesn’t have such a placeholder, so the fake terminal
    script is spawned twice in quick succession, once for each URI. Since it
    was making two separate printf calls (one to print the output to the
    pipe, and one to terminate it with a newline), it’s possible that two
    invocations of the script could interleave their printf calls, resulting
    in pipe input along the lines of `URI1 URI2 newline newline` rather than
    `URI1 newline URI2 newline`.
    
    This would cause the test to fail.
    
    Fix that by making the script atomic by moving the newline into the
    first printf call.
    
    See: https://gitlab.gnome.org/GNOME/glib/-/jobs/2339109:
    ```
    \# Fake 'nxterm' terminal created as: /tmp/bin-path-R6GWT1/nxterm
    \# 'nxterm' called with arguments: '-e true nxterm-argument /tmp/bin-path-R6GWT1-e true nxterm-argument 
/tmp/test_desktop-app-info_CO92T1/desktop-app-info/launch-uris-with-terminal/nxterm/.dirs/data'
    Bail out! GLib-GIO:ERROR:../gio/tests/desktop-app-info.c:1294:test_launch_uris_with_terminal: assertion 
failed (g_strv_length (output_args) == 4): (7 == 4)
    ```
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/tests/desktop-app-info.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
---
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index f49db4af7d..cd23aa213c 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -1253,8 +1253,7 @@ test_launch_uris_with_terminal (gconstpointer data)
   data_input_stream = g_data_input_stream_new (input_stream);
   script_contents = g_strdup_printf ("#!%s\n" \
                                      "out='%s'\n"
-                                     "printf '%%s' \"$*\" > \"$out\"\n"
-                                     "printf '\\n' > \"$out\"\n",
+                                     "printf '%%s\\n' \"$*\" > \"$out\"\n",
                                      sh,
                                      output_fd_path);
   g_file_set_contents (terminal_path, script_contents, -1, &error);


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