Merge lp:~dobey/ubuntuone-dev-tools/dbus-priv into lp:ubuntuone-dev-tools

Proposed by dobey
Status: Merged
Approved by: Natalia Bidart
Approved revision: 33
Merged at revision: 33
Proposed branch: lp:~dobey/ubuntuone-dev-tools/dbus-priv
Merge into: lp:ubuntuone-dev-tools
Diff against target: 35 lines (+16/-1)
1 file modified
ubuntuone/devtools/testcase.py (+16/-1)
To merge this branch: bzr merge lp:~dobey/ubuntuone-dev-tools/dbus-priv
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+63022@code.launchpad.net

Commit message

Check that DBUS_SESSION_BUS_ADDRESS is setup correctly for tests
Fail the tests if the address doesn't point to a private instance
Pass the address directly into the BusConnection()

Description of the change

This makes the DBus test cases fail if the session bus address is wrong, and should always connect to the right daemon, since it passes in the address directly.

However, I would like to add a check for number of connections to the daemon, so that if we connect, and there are a bunch of existing connections, the test will fail, because it's probably connecting to the wrong thing, and/or the previous run tests aren't getting cleaned up properly and their connections closed. Unfortunately, it seems there is a larger problem where the previous run tests aren't getting their connections closed properly, and so stay connected to the bus and instantiated in memory.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Thanks!

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/devtools/testcase.py'
2--- ubuntuone/devtools/testcase.py 2011-05-24 21:54:50 +0000
3+++ ubuntuone/devtools/testcase.py 2011-05-31 17:46:00 +0000
4@@ -129,6 +129,10 @@
5 # pylint: enable=C0103
6
7
8+class InvalidSessionBus(Exception):
9+ """Error when we are connected to the wrong session bus in tests."""
10+
11+
12 class FakeDBusInterface(object):
13 """A fake DBusInterface..."""
14
15@@ -217,8 +221,19 @@
16 # dbus modules will be imported by the decorator
17 # pylint: disable=E0602
18 yield super(DBusTestCase, self).setUp()
19+
20+ # We need to ensure DBUS_SESSION_BUS_ADDRESS is private here
21+ from urllib import unquote
22+ bus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS', None)
23+ if os.path.dirname(unquote(bus_address.split(',')[0].split('=')[1])) \
24+ != os.path.dirname(os.getcwd()):
25+ raise InvalidSessionBus('DBUS_SESSION_BUS_ADDRES is wrong.')
26+
27+ # Set up the main loop and bus connection
28 self.loop = DBusGMainLoop(set_as_default=True)
29- self.bus = dbus.bus.BusConnection(mainloop=self.loop)
30+ self.bus = dbus.bus.BusConnection(address_or_type=bus_address,
31+ mainloop=self.loop)
32+
33 # monkeypatch busName.__del__ to avoid errors on gc
34 # we take care of releasing the name in shutdown
35 service.BusName.__del__ = lambda _: None

Subscribers

People subscribed via source and target branches

to all changes: