summaryrefslogtreecommitdiff
path: root/gio
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@endlessos.org>2023-03-22 14:50:55 +0000
committerPhilip Withnall <pwithnall@endlessos.org>2023-03-22 15:12:52 +0000
commit666c72c9c5bff66c023aad806dc8f46f3da89cb4 (patch)
tree6f2b57ec058b70044945278fd3b88242b5165b8c /gio
parentc0ca3f995ba7755c797f15981429ba4156afc8ed (diff)
downloadglib-666c72c9c5bff66c023aad806dc8f46f3da89cb4.tar.gz
tests: Fix non-removal of a timeout in appmonitor test
If the first part of the test takes less than 3s (which is normal), the timeout for it is not removed, and could spuriously fire during the second part of the test, causing a false failure. Instead of relying on source IDs, just use (and explicitly destroy) a `GSource` for the timeouts. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Diffstat (limited to 'gio')
-rw-r--r--gio/tests/appmonitor.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/gio/tests/appmonitor.c b/gio/tests/appmonitor.c
index e973b990d..e20860cec 100644
--- a/gio/tests/appmonitor.c
+++ b/gio/tests/appmonitor.c
@@ -105,6 +105,8 @@ test_app_monitor (Fixture *fixture,
gchar *app_path;
GAppInfoMonitor *monitor;
GMainLoop *loop;
+ GMainContext *context = NULL; /* use the global default main context */
+ GSource *timeout_source = NULL;
GDesktopAppInfo *app = NULL;
app_path = g_build_filename (fixture->applications_dir, "app.desktop", NULL);
@@ -113,24 +115,31 @@ test_app_monitor (Fixture *fixture,
g_list_free_full (g_app_info_get_all (), g_object_unref);
monitor = g_app_info_monitor_get ();
- loop = g_main_loop_new (NULL, FALSE);
+ loop = g_main_loop_new (context, FALSE);
g_signal_connect (monitor, "changed", G_CALLBACK (changed_cb), loop);
g_idle_add (create_app, app_path);
- g_timeout_add_seconds (3, quit_loop, loop);
+ timeout_source = g_timeout_source_new_seconds (3);
+ g_source_set_callback (timeout_source, quit_loop, loop, NULL);
+ g_source_attach (timeout_source, NULL);
g_main_loop_run (loop);
g_assert_true (changed_fired);
changed_fired = FALSE;
+ g_source_destroy (timeout_source);
+ g_clear_pointer (&timeout_source, g_source_unref);
+
/* Check that the app is now queryable. This has the side-effect of re-arming
* the #GAppInfoMonitor::changed signal for the next part of the test. */
app = g_desktop_app_info_new ("app.desktop");
g_assert_nonnull (app);
g_clear_object (&app);
- g_timeout_add_seconds (3, quit_loop, loop);
+ timeout_source = g_timeout_source_new_seconds (3);
+ g_source_set_callback (timeout_source, quit_loop, loop, NULL);
+ g_source_attach (timeout_source, NULL);
delete_app (app_path);
@@ -138,6 +147,8 @@ test_app_monitor (Fixture *fixture,
g_assert_true (changed_fired);
+ g_source_destroy (timeout_source);
+ g_clear_pointer (&timeout_source, g_source_unref);
g_main_loop_unref (loop);
g_remove (app_path);