summaryrefslogtreecommitdiff
path: root/test/name-test
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-12-14 18:12:24 -0500
committerColin Walters <walters@verbum.org>2010-01-28 17:01:24 -0500
commitb7e77c6b035f634f372c1749e61c14bde18b5d95 (patch)
tree2e7cc5c81b41e3b287bdd53e3b37dc7cd1d6104b /test/name-test
parenta8e620a0ff60eef983a9be95e2b27dbcdcbaf654 (diff)
Ignore exit code zero from activated services
A variety of system components have migrated from legacy init into DBus service activation. Many of these system components "daemonize", which involves forking. The DBus activation system treated an exit as an activation failure, assuming that the child process which grabbed the DBus name didn't run first. While we're in here, also differentiate in this code path between the servicehelper (system) versus direct activation (session) paths. In the session activation path our error message mentioned a helper process which was confusing, since none was involved. Based on a patch and debugging research from Ray Strode <rstrode@redhat.com>
Diffstat (limited to 'test/name-test')
-rw-r--r--test/name-test/Makefile.am2
-rwxr-xr-xtest/name-test/run-test.sh6
-rw-r--r--test/name-test/test-activation-forking.py60
3 files changed, 67 insertions, 1 deletions
diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am
index 1c73b877..d8e72d14 100644
--- a/test/name-test/Makefile.am
+++ b/test/name-test/Makefile.am
@@ -10,7 +10,7 @@ else
TESTS=
endif
-EXTRA_DIST=run-test.sh run-test-systemserver.sh test-wait-for-echo.py
+EXTRA_DIST=run-test.sh run-test-systemserver.sh test-wait-for-echo.py test-activation-forking.py
if DBUS_BUILD_TESTS
diff --git a/test/name-test/run-test.sh b/test/name-test/run-test.sh
index fba45584..4eb24252 100755
--- a/test/name-test/run-test.sh
+++ b/test/name-test/run-test.sh
@@ -50,3 +50,9 @@ ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-
echo "running test-shutdown"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-shutdown || die "test-shutdown failed"
+
+echo "running test activation forking"
+if ! python $DBUS_TOP_SRCDIR/test/name-test/test-activation-forking.py; then
+ echo "Failed test-activation-forking"
+ exit 1
+fi
diff --git a/test/name-test/test-activation-forking.py b/test/name-test/test-activation-forking.py
new file mode 100644
index 00000000..0d820754
--- /dev/null
+++ b/test/name-test/test-activation-forking.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+import os,sys
+
+try:
+ import gobject
+ import dbus
+ import dbus.mainloop.glib
+except:
+ print "Failed import, aborting test"
+ sys.exit(0)
+
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+loop = gobject.MainLoop()
+
+exitcode = 0
+
+bus = dbus.SessionBus()
+bus_iface = dbus.Interface(bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus'), 'org.freedesktop.DBus')
+
+o = bus.get_object('org.freedesktop.DBus.TestSuiteForkingEchoService', '/org/freedesktop/TestSuite')
+i = dbus.Interface(o, 'org.freedesktop.TestSuite')
+
+# Start it up
+reply = i.Echo("hello world")
+print "TestSuiteForkingEchoService initial reply OK"
+
+def ignore(*args, **kwargs):
+ pass
+
+# Now monitor for exits, when that happens, start it up again.
+# The goal here is to try to hit any race conditions in activation.
+counter = 0
+def on_forking_echo_owner_changed(name, old, new):
+ global counter
+ global o
+ global i
+ if counter > 10:
+ print "Activated 10 times OK, TestSuiteForkingEchoService pass"
+ loop.quit()
+ return
+ counter += 1
+ if new == '':
+ o = bus.get_object('org.freedesktop.DBus.TestSuiteForkingEchoService', '/org/freedesktop/TestSuite')
+ i = dbus.Interface(o, 'org.freedesktop.TestSuite')
+ i.Echo("counter %r" % counter)
+ i.Exit(reply_handler=ignore, error_handler=ignore)
+
+bus_iface.connect_to_signal('NameOwnerChanged', on_forking_echo_owner_changed, arg0='org.freedesktop.DBus.TestSuiteForkingEchoService')
+
+i.Exit(reply_handler=ignore, error_handler=ignore)
+
+def check_counter():
+ if counter == 0:
+ print "Failed to get NameOwnerChanged for TestSuiteForkingEchoService"
+ sys.exit(1)
+gobject.timeout_add(15000, check_counter)
+
+loop.run()
+sys.exit(0)