gdbus-peer test: let GDBusServer start before notifying main thread
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Thu, 7 May 2015 15:45:48 +0000 (16:45 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 11 May 2015 13:17:55 +0000 (14:17 +0100)
commit6f859fe21a1955ab60ba4aa7e22841c7dbffdea3
tree73ad2cc95b35cffa2350d052c49469dbdee8bec1
parent474877d916439e20769a4aad4bccdedff2ad04ac
gdbus-peer test: let GDBusServer start before notifying main thread

When running the nonce-tcp and tcp-anonymous tests in one run
of gdbus-peer, or running one of them twice via command-line options
"-p /gdbus/tcp-anonymous -p /gdbus/tcp-anonymous", the one run second
would sometimes fail to connect with ECONNRESET.

Adding more debug messages revealed that in the successful case,
g_main_loop_run() was executed in the server thread first:

 # tcp-anonymous: server thread: listening on tcp:host=localhost,port=53517
 # tcp-anonymous: server thread: starting server...
 # tcp-anonymous: server thread: creating main loop...
 # tcp-anonymous: server thread: running main loop...
 # tcp-anonymous: main thread: trying tcp:host=localhost,port=53517...
 # tcp-anonymous: main thread: waiting for server thread...

but in the failing case, the main thread attempted to connect
before the call to g_main_loop_run() in the server thread:

 # tcp-anonymous: server thread: listening on tcp:host=localhost,port=40659
 # tcp-anonymous: server thread: starting server...
 # tcp-anonymous: server thread: creating main loop...
 # tcp-anonymous: main thread: trying tcp:host=localhost,port=40659...
 # tcp-anonymous: server thread: running main loop...

(The log message "creating main loop" was immediately before
create_service_loop(), and "running main loop" was immediately
before g_main_loop_run().)

To ensure that the GDBusServer has a chance to start accepting
connections before the main thread tries to connect to it, do not
tell the main thread about the service_loop immediately, but instead
defer it to an idle.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=749079
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
gio/tests/gdbus-peer.c