gdbusconnection: Fix test signal subscription ordering

The test case assumes signals will dispatched in a different order than
they're subscribed. In fact, signals can be dispatched in any order,
and are often dispatched in order.

This commit reorders the subscriptions so they're in order, which is
more logical, and also changes the code to only exit the event loops
when there are no pending handlers ready to dispatch.
This commit is contained in:
Ray Strode 2024-05-07 15:31:47 -04:00
parent d22c4574cd
commit 47866d252f

View File

@ -536,7 +536,12 @@ test_connection_signal_handler (GDBusConnection *connection,
interface_name,
signal_name);*/
g_main_loop_quit (loop);
/* We defer quitting to a G_PRIORITY_DEFAULT_IDLE function so other queued signal
* callbacks have a chance to run first. They get dispatched with a higher priority
* of G_PIORITY_DEFAULT, so as long as the queue is non-empty g_main_loop_quit won't
* run
*/
g_idle_add_once ((GSourceOnceFunc) g_main_loop_quit, loop);
}
static void
@ -627,7 +632,7 @@ test_connection_signals (void)
"org.gtk.GDBus.ExampleInterface", /* interface */
"FooArg0", /* member */
"/org/gtk/GDBus/ExampleInterface", /* path */
"some-arg0",
NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
test_connection_signal_handler,
&count_s4,
@ -637,7 +642,7 @@ test_connection_signals (void)
"org.gtk.GDBus.ExampleInterface", /* interface */
"FooArg0", /* member */
"/org/gtk/GDBus/ExampleInterface", /* path */
NULL,
"some-arg0",
G_DBUS_SIGNAL_FLAGS_NONE,
test_connection_signal_handler,
&count_s5,
@ -741,8 +746,8 @@ test_connection_signals (void)
g_assert_cmpint (count_s2, ==, 2);
/* Emit another signal on c2 with and without arg0 set, to check matching on that.
* Matching should fail on s4 when the signal is not emitted with an arg0. It
* should succeed on s5 both times, as that doesnt require an arg0 match. */
* Matching should fail on s5 when the signal is not emitted with an arg0. It
* should succeed on s4 both times, as that doesnt require an arg0 match. */
ret = g_dbus_connection_emit_signal (c2,
NULL, /* destination bus name */
"/org/gtk/GDBus/ExampleInterface",
@ -753,9 +758,9 @@ test_connection_signals (void)
g_assert_no_error (error);
g_assert_true (ret);
while (count_s5 < 1)
while (count_s4 < 1)
g_main_loop_run (loop);
g_assert_cmpint (count_s5, ==, 1);
g_assert_cmpint (count_s4, ==, 1);
ret = g_dbus_connection_emit_signal (c2,
NULL, /* destination bus name */
@ -767,10 +772,10 @@ test_connection_signals (void)
g_assert_no_error (error);
g_assert_true (ret);
while (count_s4 < 1)
while (count_s5 < 1)
g_main_loop_run (loop);
g_assert_cmpint (count_s4, ==, 1);
g_assert_cmpint (count_s5, ==, 2);
g_assert_cmpint (count_s4, ==, 2);
g_assert_cmpint (count_s5, ==, 1);
/*
* Also to check the total amount of NameOwnerChanged signals - use a 5 second ceiling
@ -784,8 +789,8 @@ test_connection_signals (void)
g_assert_cmpint (count_s1, ==, 1);
g_assert_cmpint (count_s2, ==, 2);
g_assert_cmpint (count_name_owner_changed, ==, 2);
g_assert_cmpint (count_s4, ==, 1);
g_assert_cmpint (count_s5, ==, 2);
g_assert_cmpint (count_s4, ==, 2);
g_assert_cmpint (count_s5, ==, 1);
g_dbus_connection_signal_unsubscribe (c1, s1);
g_dbus_connection_signal_unsubscribe (c1, s2);