mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
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-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=884661 https://bugzilla.gnome.org/show_bug.cgi?id=791744
This commit is contained in:
parent
ea159a9e1a
commit
8fef0a9cd3
@ -1070,32 +1070,42 @@ do_subscriptions (GDBusConnection *exporter_connection,
|
|||||||
|
|
||||||
g_assert_cmpint (items_changed_count, ==, 0);
|
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_timeout_add (100, stop_loop, loop);
|
||||||
g_main_loop_run (loop);
|
g_main_loop_run (loop);
|
||||||
|
|
||||||
|
/* Looking at the items triggers subscription */
|
||||||
g_menu_model_get_n_items (G_MENU_MODEL (proxy));
|
g_menu_model_get_n_items (G_MENU_MODEL (proxy));
|
||||||
|
|
||||||
g_timeout_add (100, stop_loop, loop);
|
while (items_changed_count < 1)
|
||||||
g_main_loop_run (loop);
|
g_main_context_iteration (NULL, TRUE);
|
||||||
|
|
||||||
|
/* We get all three items in one batch */
|
||||||
g_assert_cmpint (items_changed_count, ==, 1);
|
g_assert_cmpint (items_changed_count, ==, 1);
|
||||||
g_assert_cmpint (g_menu_model_get_n_items (G_MENU_MODEL (proxy)), ==, 3);
|
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_timeout_add (100, stop_loop, loop);
|
||||||
g_main_loop_run (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, "item4", NULL);
|
||||||
g_menu_append (menu, "item5", NULL);
|
g_menu_append (menu, "item5", NULL);
|
||||||
g_menu_append (menu, "item6", NULL);
|
g_menu_append (menu, "item6", NULL);
|
||||||
g_menu_remove (menu, 0);
|
g_menu_remove (menu, 0);
|
||||||
g_menu_remove (menu, 0);
|
g_menu_remove (menu, 0);
|
||||||
|
|
||||||
g_timeout_add (200, stop_loop, loop);
|
while (items_changed_count < 6)
|
||||||
g_main_loop_run (loop);
|
g_main_context_iteration (NULL, TRUE);
|
||||||
|
|
||||||
g_assert_cmpint (items_changed_count, ==, 6);
|
g_assert_cmpint (items_changed_count, ==, 6);
|
||||||
|
|
||||||
g_assert_cmpint (g_menu_model_get_n_items (G_MENU_MODEL (proxy)), ==, 4);
|
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_object_unref (proxy);
|
||||||
|
|
||||||
g_timeout_add (100, stop_loop, loop);
|
g_timeout_add (100, stop_loop, loop);
|
||||||
|
Loading…
Reference in New Issue
Block a user