mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-01 21:33:09 +02:00
tests/mainloop: iterate for a little while for timeout-once
On win32, WaitForSingleObject may return before the timeout is dispatched, as it doesn't have a resolution higher than the system tick. Wait for ~50ms before checking the callback changes. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
17ac6642c7
commit
1a29fd4308
@ -2349,6 +2349,7 @@ test_maincontext_timeout_once (void)
|
|||||||
{
|
{
|
||||||
guint counter = 0, check_counter = 0;
|
guint counter = 0, check_counter = 0;
|
||||||
guint source_id;
|
guint source_id;
|
||||||
|
gint64 t;
|
||||||
GSource *source;
|
GSource *source;
|
||||||
|
|
||||||
g_test_summary ("Test g_timeout_add_once() works");
|
g_test_summary ("Test g_timeout_add_once() works");
|
||||||
@ -2360,14 +2361,18 @@ test_maincontext_timeout_once (void)
|
|||||||
|
|
||||||
/* Iterating the main context should dispatch the source, though we have to block. */
|
/* Iterating the main context should dispatch the source, though we have to block. */
|
||||||
g_assert_cmpuint (counter, ==, 0);
|
g_assert_cmpuint (counter, ==, 0);
|
||||||
g_main_context_iteration (NULL, TRUE);
|
t = g_get_monotonic_time ();
|
||||||
|
while (g_get_monotonic_time () - t < 50 * 1000 && counter == 0)
|
||||||
|
g_main_context_iteration (NULL, TRUE);
|
||||||
g_assert_cmpuint (counter, ==, 1);
|
g_assert_cmpuint (counter, ==, 1);
|
||||||
|
|
||||||
/* Iterating it again should not dispatch the source again. We add a second
|
/* Iterating it again should not dispatch the source again. We add a second
|
||||||
* timeout and block until that is dispatched. Given the ordering guarantees,
|
* timeout and block until that is dispatched. Given the ordering guarantees,
|
||||||
* we should then know whether the first one would have re-dispatched by then. */
|
* we should then know whether the first one would have re-dispatched by then. */
|
||||||
g_timeout_add_once (30 /* ms */, once_cb, &check_counter);
|
g_timeout_add_once (30 /* ms */, once_cb, &check_counter);
|
||||||
g_main_context_iteration (NULL, TRUE);
|
t = g_get_monotonic_time ();
|
||||||
|
while (g_get_monotonic_time () - t < 50 * 1000 && check_counter == 0)
|
||||||
|
g_main_context_iteration (NULL, TRUE);
|
||||||
g_assert_cmpuint (check_counter, ==, 1);
|
g_assert_cmpuint (check_counter, ==, 1);
|
||||||
g_assert_cmpuint (counter, ==, 1);
|
g_assert_cmpuint (counter, ==, 1);
|
||||||
g_assert_true (g_source_is_destroyed (source));
|
g_assert_true (g_source_is_destroyed (source));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user