mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-28 18:16:34 +02:00
tests: Use file monitoring to wait for file creation
Doing this is faster and also means that the mainloop will be iterated while the test is waiting for file creation. The mainloop iteration is necessary as GLib may need to wait for a DBus reply from systemd before the application is executed.
This commit is contained in:
@@ -324,20 +324,16 @@ wait_for_file (const gchar *want_this,
|
|||||||
const gchar *but_not_this,
|
const gchar *but_not_this,
|
||||||
const gchar *or_this)
|
const gchar *or_this)
|
||||||
{
|
{
|
||||||
guint retries = 600;
|
GFile *file = g_file_new_for_path (want_this);
|
||||||
|
GFileMonitor *monitor;
|
||||||
|
|
||||||
|
monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||||
|
g_object_unref (file);
|
||||||
|
|
||||||
/* I hate time-based conditions in tests, but this will wait up to one
|
|
||||||
* whole minute for "touch file" to finish running. I think it should
|
|
||||||
* be OK.
|
|
||||||
*
|
|
||||||
* 600 * 100ms = 60 seconds.
|
|
||||||
*/
|
|
||||||
while (access (want_this, F_OK) != 0)
|
while (access (want_this, F_OK) != 0)
|
||||||
{
|
g_main_context_iteration (NULL, TRUE);
|
||||||
g_usleep (100000); /* 100ms */
|
|
||||||
g_assert_cmpuint (retries, >, 0);
|
g_object_unref (monitor);
|
||||||
retries--;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert_cmpuint (access (but_not_this, F_OK), !=, 0);
|
g_assert_cmpuint (access (but_not_this, F_OK), !=, 0);
|
||||||
g_assert_cmpuint (access (or_this, F_OK), !=, 0);
|
g_assert_cmpuint (access (or_this, F_OK), !=, 0);
|
||||||
|
Reference in New Issue
Block a user