CHROMIUM: test_util_common: Wait for both D-Bus path and service name

Tests that run an Upstart instance use the wait_for_upstart() helper,
which tries to wait for Upstart to be available on D-Bus. However, this
helper only waits for any /com/ubuntu/Upstart path to be available; it
doesn't actually look for the com.ubuntu.Upstart service name.

This can be a problem for some tests [1], because as control_bus_open()
notes, we purposely register the service name last as a signal to
clients -- any time before that, we may have partially registered our
objects, and initctl clients may still fail.

The solution here is to look up the owner name too, by providing the
"well known service name" to libnih, and checking for a non-NULL
NihDBusProxy::owner result. This only works for non-"session init",
because the private session bus is a peer-to-peer D-Bus connection [2].

For "session init" (with a peer-to-peer connection), callers tend to
call set_upstart_session() already, which polls over `initctl` calls.

While solving this bug, also remove some excess first-loop sleeps which
help to hide these kinds of problems. And augment _start_upstart() such
that it skips D-Bus checks when run with --no-dbus -- these tests (e.g.,
test_no_dbus()) would now fail.

[1] Particularly, test case failure "System Init without --confdir",
where we start Upstart, wait for D-Bus, and immediately run `initctl`
commands. We can see test failures easily if we inject extra delay into
control_register_all() or similar:

...System Init without --confdir
BAD: wrong value for lines, expected 3 got 1
        at tests/test_main.c:677 (test_confdir).
FAIL test_main (exit status: 134)

[2] A "peer to peer" connection may not support the "message bus name"
and related concepts from here:
https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus

BUG=b:332653406
BUG=b:232122437
TEST=`FEATURES=test emerge-${BOARD} upstart`
TEST=manual tweaks; see above

Change-Id: Ica734f89c00fba566f4d47f6ce47b8c8639efa36
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/upstart/+/5427194
Tested-by: Brian Norris <[email protected]>
Commit-Queue: Brian Norris <[email protected]>
Reviewed-by: Allen Webb <[email protected]>
1 file changed