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

Proposed by dobey
Status: Merged
Approved by: Tim Cole
Approved revision: 34
Merged at revision: 34
Proposed branch: lp:~dobey/ubuntuone-dev-tools/dbus-strict-priv
Merge into: lp:ubuntuone-dev-tools
Diff against target: 93 lines (+13/-46)
1 file modified
ubuntuone/devtools/testcase.py (+13/-46)
To merge this branch: bzr merge lp:~dobey/ubuntuone-dev-tools/dbus-strict-priv
Reviewer Review Type Date Requested Status
Tim Cole (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+63134@code.launchpad.net

Commit message

Be more strict about connection to the dbus service, and cleanup of connections
Just enforce disconnection from the bus, rather than trying to remove signals
Don't do inlineCallbacks for now, as it seems to cause many problems

Description of the change

I've gone and removed the inlineCallbacks decorator here, because it seems to create a lot more problems than it is supposed to solve, and the tests in devtools, sso-client, control-panel, and ubuntuone-client all pass without it, while having it makes the additional strictness introduced here cause failures in sso-client and control-panel, because the deferred usage seems to cause race conditions with cleanup of connections to the dbus daemon. And without the decorator, everything seems to just work, as expected, save a few minor other details in a few of the other projects. The tests all pass, but in a couple cases, there is some very weird usage of various test case imports, and MI.

And I think it is better to work everywhere now, as expected, than to just be broken everywhere, because twisted forces us to be broken; so I'm proposing this as it is.

This change is however, set up so that @inlineCallbacks can be added back to the setUp/tearDown when all the other issues are fixed, and it does in fact work correctly.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good

review: Approve
Revision history for this message
Tim Cole (tcole) :
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-31 17:35:49 +0000
3+++ ubuntuone/devtools/testcase.py 2011-06-01 15:39:31 +0000
4@@ -27,8 +27,6 @@
5
6 from functools import wraps
7
8-from twisted.internet import defer
9-from twisted.python import failure
10 from twisted.trial.unittest import TestCase, SkipTest
11
12 # DBusRunner for DBusTestCase using tests
13@@ -213,7 +211,6 @@
14 services.extend([DBusRunner])
15 return services
16
17- @defer.inlineCallbacks
18 def setUp(self):
19 """Setup the infrastructure fo the test (dbus service)."""
20 # Class 'BaseTestCase' has no 'setUp' member
21@@ -224,59 +221,29 @@
22
23 # We need to ensure DBUS_SESSION_BUS_ADDRESS is private here
24 from urllib import unquote
25- bus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS', None)
26+ bus_address = yield os.environ.get('DBUS_SESSION_BUS_ADDRESS', None)
27 if os.path.dirname(unquote(bus_address.split(',')[0].split('=')[1])) \
28 != os.path.dirname(os.getcwd()):
29 raise InvalidSessionBus('DBUS_SESSION_BUS_ADDRES is wrong.')
30
31 # Set up the main loop and bus connection
32- self.loop = DBusGMainLoop(set_as_default=True)
33- self.bus = dbus.bus.BusConnection(address_or_type=bus_address,
34- mainloop=self.loop)
35+ self.loop = yield DBusGMainLoop(set_as_default=True)
36+ self.bus = yield dbus.bus.BusConnection(address_or_type=bus_address,
37+ mainloop=self.loop)
38+
39+ # Check that we are on the correct bus for real
40+ if len(self.bus.list_names()) > 2:
41+ raise InvalidSessionBus('Too many bus connections: %s' %
42+ len(self.bus.list_names()))
43
44 # monkeypatch busName.__del__ to avoid errors on gc
45 # we take care of releasing the name in shutdown
46 service.BusName.__del__ = lambda _: None
47- self.bus.set_exit_on_disconnect(False)
48+ yield self.bus.set_exit_on_disconnect(False)
49 self.signal_receivers = set()
50
51 def tearDown(self):
52 """Cleanup the test."""
53- # Class 'BaseTestCase' has no 'tearDown' member
54- # pylint: disable=E1101
55- d = self.cleanup_signal_receivers(self.signal_receivers)
56- d.addBoth(self._tear_down)
57- d.addBoth(lambda _: super(DBusTestCase, self).tearDown())
58- return d
59-
60- def _tear_down(self):
61- """Shutdown."""
62- self.bus.flush()
63- self.bus.close()
64-
65- def error_handler(self, error):
66- """Default error handler for DBus calls."""
67- if isinstance(error, failure.Failure):
68- self.fail(error.getErrorMessage())
69-
70- def cleanup_signal_receivers(self, signal_receivers):
71- """Cleanup self.signal_receivers and returns a deferred."""
72- # dbus modules will be imported by the decorator
73- # pylint: disable=E0602
74- deferreds = []
75- for match in signal_receivers:
76- d = defer.Deferred()
77-
78- def callback(*args):
79- """Callback that accepts *args."""
80- if not d.called:
81- d.callback(args)
82- self.bus.call_async(dbus.bus.BUS_DAEMON_NAME,
83- dbus.bus.BUS_DAEMON_PATH,
84- dbus.bus.BUS_DAEMON_IFACE, 'RemoveMatch', 's',
85- (str(match),), callback, self.error_handler)
86- deferreds.append(d)
87- if deferreds:
88- return defer.DeferredList(deferreds)
89- else:
90- return defer.succeed(True)
91+ yield self.bus.flush()
92+ yield self.bus.close()
93+ yield super(DBusTestCase, self).tearDown()

Subscribers

People subscribed via source and target branches

to all changes: