[glib/glib-2-54] gmenumodel test: Wait for the expected events to happen
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-54] gmenumodel test: Wait for the expected events to happen
- Date: Thu, 21 Dec 2017 10:51:40 +0000 (UTC)
commit da4cdc6890152a45ca2a207c6ffa42337371299b
Author: Simon McVittie <smcv collabora com>
Date: Tue Dec 19 12:53:00 2017 +0000
gmenumodel test: Wait for the expected events to happen
Previously, we waited an arbitrary 100ms or 200ms and then asserted
that the events had happened, but that might fail if the machine is
slow or heavily loaded.
We still wait for an arbitrary time for negative tests (asserting
that no more signals are received) because we don't have any way
to do better here.
Signed-off-by: Simon McVittie <smcv collabora com>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=791744
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=884661
gio/tests/gmenumodel.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/gio/tests/gmenumodel.c b/gio/tests/gmenumodel.c
index d18103b..f18db77 100644
--- a/gio/tests/gmenumodel.c
+++ b/gio/tests/gmenumodel.c
@@ -868,32 +868,42 @@ test_dbus_subscriptions (void)
g_assert_cmpint (items_changed_count, ==, 0);
+ /* We don't subscribe to change-notification until we look at the items */
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
+ /* Looking at the items triggers subscription */
g_menu_model_get_n_items (G_MENU_MODEL (proxy));
- g_timeout_add (100, stop_loop, loop);
- g_main_loop_run (loop);
+ while (items_changed_count < 1)
+ g_main_context_iteration (NULL, TRUE);
+ /* We get all three items in one batch */
g_assert_cmpint (items_changed_count, ==, 1);
g_assert_cmpint (g_menu_model_get_n_items (G_MENU_MODEL (proxy)), ==, 3);
+ /* If we wait, we don't get any more */
g_timeout_add (100, stop_loop, loop);
g_main_loop_run (loop);
+ g_assert_cmpint (items_changed_count, ==, 1);
+ g_assert_cmpint (g_menu_model_get_n_items (G_MENU_MODEL (proxy)), ==, 3);
+ /* Now we're subscribed, we get changes individually */
g_menu_append (menu, "item4", NULL);
g_menu_append (menu, "item5", NULL);
g_menu_append (menu, "item6", NULL);
g_menu_remove (menu, 0);
g_menu_remove (menu, 0);
- g_timeout_add (200, stop_loop, loop);
- g_main_loop_run (loop);
+ while (items_changed_count < 6)
+ g_main_context_iteration (NULL, TRUE);
g_assert_cmpint (items_changed_count, ==, 6);
g_assert_cmpint (g_menu_model_get_n_items (G_MENU_MODEL (proxy)), ==, 4);
+
+ /* After destroying the proxy and waiting a bit, we don't get any more
+ * items-changed signals */
g_object_unref (proxy);
g_timeout_add (100, stop_loop, loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]