Merge lp:~mikemc/ubuntuone-client/fix-networkstate-manythreads into lp:ubuntuone-client

Proposed by Mike McCracken
Status: Merged
Approved by: dobey
Approved revision: 1369
Merged at revision: 1367
Proposed branch: lp:~mikemc/ubuntuone-client/fix-networkstate-manythreads
Merge into: lp:ubuntuone-client
Prerequisite: lp:~mikemc/ubuntuone-client/use-IPCError-in-PB
Diff against target: 61 lines (+21/-2)
1 file modified
tests/platform/ipc/test_perspective_broker.py (+21/-2)
To merge this branch: bzr merge lp:~mikemc/ubuntuone-client/fix-networkstate-manythreads
Reviewer Review Type Date Requested Status
dobey (community) Approve
Review via email: mp+142348@code.launchpad.net

Commit message

- Mock out NetworkState in IPCTestCase, avoids starting a thread per test case on darwin and windows.

Description of the change

- Mock out NetworkState in IPCTestCase, avoids starting a thread per test case on darwin and windows.

Since IPCTestCase subclasses do not test network state handling, a simple mock that always returns ONLINE works fine, and avoids starting a ton of threads that never exit.

This appears to be more of a problem on darwin than on windows, but it can't hurt.

To post a comment you must log in.
Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/ipc/test_perspective_broker.py'
2--- tests/platform/ipc/test_perspective_broker.py 2012-09-06 22:17:45 +0000
3+++ tests/platform/ipc/test_perspective_broker.py 2013-01-08 16:55:32 +0000
4@@ -78,6 +78,7 @@
5 )
6 from ubuntuone.syncdaemon import interaction_interfaces
7
8+from ubuntu_sso.networkstate.networkstates import ONLINE
9
10 TEST_PORT = 40404
11 TEST_DOMAIN_SOCKET = os.path.join(basedir.xdg_cache_home, 'ubuntuone', 'ipc')
12@@ -351,6 +352,18 @@
13 self.called.append(args)
14
15
16+class FakeNetworkManagerState(object):
17+ """Fake NetworkState."""
18+
19+ def __init__(self, result_cb=None):
20+ """Just save callback."""
21+ self.cb = result_cb
22+
23+ def find_online_state(self):
24+ """Always say ONLINE."""
25+ self.cb(ONLINE)
26+
27+
28 class RemoteClientTestCase(TestCase):
29 """Tests for the RemoteClient class."""
30
31@@ -381,7 +394,8 @@
32 self.patch(ipc, 'ActivationClient', FakeActivationClient)
33 # patch the interaction interfaces to not choose the system one but
34 # always the perspective broker one
35- self.patch(interaction_interfaces, 'ExternalInterface', ipc.IPCInterface)
36+ self.patch(interaction_interfaces, 'ExternalInterface',
37+ ipc.IPCInterface)
38
39 yield super(IPCTestCase, self).setUp()
40
41@@ -399,6 +413,11 @@
42
43 self.bus = None # parity with linux code
44
45+ # patch the networkmanagerstate to avoid spawning unnecessary
46+ # threads when we instantiate the syncdaemonservice:
47+ self.patch(interaction_interfaces, 'NetworkManagerState',
48+ FakeNetworkManagerState)
49+
50 self.service = self.service_class(main=self.main, send_events=True)
51 self.service.oauth_credentials = ('foo', 'bar')
52
53@@ -517,7 +536,7 @@
54 setattr(remote_client, remote_cb_name, fake_remote_cb)
55 self.addCleanup(delattr, remote_client, remote_cb_name)
56
57- remote_client_func = getattr(remote_client,
58+ remote_client_func = getattr(remote_client,
59 remote_client_func_name)
60
61 result = remote_client_func(*args)

Subscribers

People subscribed via source and target branches