tests: Connect to GMemoryMonitor signals earlier

It might be possible for the `low-memory-warning` signal to be emitted
(by the GLib worker thread) before the test has connected to it, which
could cause the tests to loop forever.

Potentially fixes
https://gitlab.gnome.org/pwithnall/glib/-/jobs/5322491, though I have
not been able to reproduce the race locally.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2025-07-22 13:33:24 +01:00
parent 89f24b81e0
commit ee5e750be3
2 changed files with 4 additions and 6 deletions

View File

@@ -65,11 +65,10 @@ test_event (const void *data)
"poll-interval-ms", 50,
"mem-free-ratio", test_data->simulated_mem_free_ratio,
NULL);
g_initable_init (G_INITABLE (monitor), NULL, &local_error);
g_assert_no_error (local_error);
warning_id = g_signal_connect (monitor, "low-memory-warning",
G_CALLBACK (memory_monitor_signal_cb), &warning_level);
g_initable_init (G_INITABLE (monitor), NULL, &local_error);
g_assert_no_error (local_error);
while (warning_level == -1)
g_main_context_iteration (NULL, TRUE);

View File

@@ -84,6 +84,8 @@ test_receive_signals (SetupData *setup, gconstpointer data)
monitor = g_object_new (G_TYPE_MEMORY_MONITOR_PSI,
"proc-path", setup->mock_proc_path,
NULL);
warning_id = g_signal_connect (monitor, "low-memory-warning",
G_CALLBACK (memory_monitor_psi_signal_cb), &warning_level);
g_initable_init (G_INITABLE (monitor), NULL, &local_error);
g_assert_no_error (local_error);
@@ -93,9 +95,6 @@ test_receive_signals (SetupData *setup, gconstpointer data)
&local_error);
g_assert_no_error (local_error);
warning_id = g_signal_connect (monitor, "low-memory-warning",
G_CALLBACK (memory_monitor_psi_signal_cb), &warning_level);
while (warning_level == -1)
g_main_context_iteration (NULL, TRUE);