From 176f66502d34cb5971df8b7d441279ca4eb6c5d3 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 1 Nov 2022 00:33:40 +0000 Subject: [PATCH] tests: Reduce an unnecessary sleep from desktop-app-info test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `g_app_info_launch_default_for_uri_async()` has already returned by this point, so waiting a long time is not really going to help. Wait for 3× as long as the successful case took, which should allow for long enough to catch true negatives, with a bit of variance. On my system, this means waiting for about 14ms, rather than the 100ms which this previous slept for. This speeds the test up by about 5%. Signed-off-by: Philip Withnall --- gio/tests/desktop-app-info.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c index cf46a00f8..a648991a7 100644 --- a/gio/tests/desktop-app-info.c +++ b/gio/tests/desktop-app-info.c @@ -1292,6 +1292,7 @@ test_default_uri_handler_async (void) GAppInfo *info; GMainLoop *loop; gboolean called = FALSE; + gint64 start_time, touch_time; loop = g_main_loop_new (NULL, FALSE); info = create_app_info_toucher ("Touch Handled", "handled-async", @@ -1300,6 +1301,7 @@ test_default_uri_handler_async (void) g_assert_true (G_IS_APP_INFO (info)); g_assert_nonnull (file_path); + start_time = g_get_real_time (); g_app_info_launch_default_for_uri_async ("glib-async-touch://touch-me", NULL, NULL, on_launch_default_for_uri_success_cb, @@ -1308,6 +1310,7 @@ test_default_uri_handler_async (void) while (!g_file_test (file_path, G_FILE_TEST_IS_REGULAR) || !called) g_main_context_iteration (NULL, FALSE); + touch_time = g_get_real_time () - start_time; g_assert_true (called); g_assert_true (g_file_test (file_path, G_FILE_TEST_IS_REGULAR)); @@ -1328,11 +1331,13 @@ test_default_uri_handler_async (void) g_cancellable_cancel (cancellable); g_main_loop_run (loop); - /* Once started our touch app may take some time before having written the - * file, so let's wait a bit here before ensuring that the file has been - * created as expected. + /* If started, our touch app would take some time to actually write the + * file to disk, so let's wait a bit here to ensure that the file isn't + * inadvertently getting created when a launch operation is canceled up + * front. Give it 3× as long as the successful case took, to allow for + * some variance. */ - g_usleep (G_USEC_PER_SEC / 10); + g_usleep (touch_time * 3); g_assert_false (g_file_test (file_path, G_FILE_TEST_IS_REGULAR)); g_object_unref (info);