test-aio: fix GSource-based timer test
The current test depends too much on the implementation of the AioContext GSource. Just iterate on the main loop until the callback has been invoked the right number of times. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
87f68d3182
commit
ef508f427b
|
@ -806,17 +806,16 @@ static void test_source_timer_schedule(void)
|
||||||
g_usleep(1 * G_USEC_PER_SEC);
|
g_usleep(1 * G_USEC_PER_SEC);
|
||||||
g_assert_cmpint(data.n, ==, 0);
|
g_assert_cmpint(data.n, ==, 0);
|
||||||
|
|
||||||
g_assert(g_main_context_iteration(NULL, false));
|
|
||||||
g_assert_cmpint(data.n, ==, 1);
|
|
||||||
|
|
||||||
/* The comment above was not kidding when it said this wakes up itself */
|
|
||||||
do {
|
|
||||||
g_assert(g_main_context_iteration(NULL, true));
|
g_assert(g_main_context_iteration(NULL, true));
|
||||||
} while (qemu_clock_get_ns(data.clock_type) <= expiry);
|
g_assert_cmpint(data.n, ==, 1);
|
||||||
g_usleep(1 * G_USEC_PER_SEC);
|
expiry += data.ns;
|
||||||
g_main_context_iteration(NULL, false);
|
|
||||||
|
while (data.n < 2) {
|
||||||
|
g_main_context_iteration(NULL, true);
|
||||||
|
}
|
||||||
|
|
||||||
g_assert_cmpint(data.n, ==, 2);
|
g_assert_cmpint(data.n, ==, 2);
|
||||||
|
g_assert(qemu_clock_get_ns(data.clock_type) > expiry);
|
||||||
|
|
||||||
aio_set_fd_handler(ctx, pipefd[0], NULL, NULL, NULL);
|
aio_set_fd_handler(ctx, pipefd[0], NULL, NULL, NULL);
|
||||||
close(pipefd[0]);
|
close(pipefd[0]);
|
||||||
|
|
Loading…
Reference in a new issue