GNOME Bugzilla – Bug 692618
Use g_timeout_add_seconds
Last modified: 2013-02-03 15:22:00 UTC
See https://live.gnome.org/GnomeGoals/UseTimeoutAddSeconds
Created attachment 234511 [details] [review] Reduce wakeups Use g_timeout_add_seconds instead of g_timeout_add wherever possible.
Comment on attachment 234511 [details] [review] Reduce wakeups Please read the comments on that GnomeGoal; g_timeout_add_seconds() is irrelevant for test programs or timeouts that only trigger once (though in some cases it's harmless and makes the code clearer), and it's explicitly wrong for "short" timeouts, since it may trigger in slightly more or less than the declared timeout time, resulting in different behavior than you intended. (Eg, switching the test program timeouts to g_timeout_add_seconds() may cause them to time out sooner, resulting in the test failing when it otherwise would have succeeded.)
Created attachment 234572 [details] [review] Reduce wakeups Use g_timeout_add_seconds instead of g_timeout_add wherever possible.
Comment on attachment 234572 [details] [review] Reduce wakeups >--- a/gio/tests/gdbus-connection.c >+++ b/gio/tests/gdbus-connection.c >@@ -234,7 +234,7 @@ test_connection_life_cycle (void) >- quit_mainloop_id = g_timeout_add (30000, test_connection_quit_mainloop, (gpointer) &quit_mainloop_fired); >+ quit_mainloop_id = g_timeout_add_seconds (30, test_connection_quit_mainloop, (gpointer) &quit_mainloop_fired); >@@ -693,7 +693,7 @@ test_connection_signals (void) >- quit_mainloop_id = g_timeout_add (30000, test_connection_quit_mainloop, &quit_mainloop_fired); >+ quit_mainloop_id = g_timeout_add_seconds (30, test_connection_quit_mainloop, &quit_mainloop_fired); >--- a/gio/tests/gdbus-tests.c >+++ b/gio/tests/gdbus-tests.c >@@ -68,7 +68,7 @@ _g_assert_property_notify_run (gpointer object, > G_CALLBACK (on_property_notify), > &data); > g_free (s); >- timeout_id = g_timeout_add (30 * 1000, >+ timeout_id = g_timeout_add_seconds (30, > on_property_notify_timeout, > &data); >@@ -117,7 +117,7 @@ _g_assert_signal_received_run (gpointer object, > signal_name, > G_CALLBACK (on_signal_received), > &data); >- timeout_id = g_timeout_add (30 * 1000, >+ timeout_id = g_timeout_add_seconds (30, > on_signal_received_timeout, > &data); >diff --git a/tests/child-test.c b/tests/child-test.c >index 9ebc202..ec36b24 100644 >--- a/tests/child-test.c >+++ b/tests/child-test.c >@@ -176,7 +176,7 @@ main (int argc, char *argv[]) >- g_timeout_add (30000, quit_loop, main_loop); >+ g_timeout_add_seconds (30, quit_loop, main_loop); > In all these, the timeout is more than 1 sec and it is recurring.
But all of these are in gio/tests/ - ie they are irrelevant to the operation of installed software. Anyway, i've taken the ones that are clearly just 'don't let the tests wait forever'.