Commit 2aea9c84 authored by Philip Withnall's avatar Philip Withnall

tests: Fix flaky socket-service test caused by GTask scheduling

On about 1 in 3 test runs, the socket-service would fail with the
ref_count assertion in connection_cb() failing (the ref_count would be 3
rather than the expected 2).

This was happening because the GTask from
g_socket_listener_accept_socket_async() now always takes at least one
main context iteration to return a result (whereas before
6f3d57d2 it might have taken zero), but
the ref_count can drop below 3 before the process of returning a result
starts. During the process of returning a result, the ref_count
temporarily increases again, which is what was breaking the test.

Fix this by waiting for one more main context iteration. This is a bit
of a hack, but the real fix would be to expose the outstanding_accept
boolean from GSocketService as public API (which the test can
interrogate), and that seems too much like exposing internal state.
Signed-off-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>

Helps: #1679
parent ffe5cdab
......@@ -222,6 +222,11 @@ test_threaded_712570 (void)
g_main_context_iteration (NULL, TRUE);
while (G_OBJECT (service)->ref_count > 3);
/* Wait some more iterations, as #GTask results are deferred to the next
* #GMainContext iteration, and propagation of a #GTask result takes an
* additional ref on the source object. */
g_main_context_iteration (NULL, FALSE);
/* Drop our ref, then unlock the mutex and wait for the service to be
* finalized. (Without the fix for 712570 it would hang forever here.)
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment