diff options
author | Simon McVittie <smcv@collabora.com> | 2017-12-18 16:56:04 +0000 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2017-12-18 18:56:35 +0000 |
commit | 8fef0a9cd3b73d995a1fd81b593a7d52fd7e693a (patch) | |
tree | 3af92be5cfcbc35776466967fe27831bbdbf4fc2 | |
parent | ea159a9e1a852246f51348ddc19353dc35727700 (diff) | |
download | glib-8fef0a9cd3b73d995a1fd81b593a7d52fd7e693a.tar.gz |
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
-rw-r--r-- | 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 fa26882db..5d6f485c4 100644 --- a/gio/tests/gmenumodel.c +++ b/gio/tests/gmenumodel.c @@ -1070,32 +1070,42 @@ do_subscriptions (GDBusConnection *exporter_connection, 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); |