[telepathy-mission-control/master] Avoid races by always waiting for the AM bus name (and the CD bus name, in most cases) to exist
Simon McVittie
simon.mcvittie at collabora.co.uk
Tue Sep 15 10:33:48 PDT 2009
---
test/twisted/account-manager/auto-connect.py | 26 +++++++++++++++--------
test/twisted/account-manager/avatar-persist.py | 26 +++++++++++++++--------
test/twisted/account-manager/avatar-refresh.py | 26 +++++++++++++++--------
test/twisted/account-manager/make-valid.py | 2 +-
test/twisted/mctest.py | 12 +++++++++++
5 files changed, 64 insertions(+), 28 deletions(-)
diff --git a/test/twisted/account-manager/auto-connect.py b/test/twisted/account-manager/auto-connect.py
index 9bafd0c..f0cb62c 100644
--- a/test/twisted/account-manager/auto-connect.py
+++ b/test/twisted/account-manager/auto-connect.py
@@ -27,7 +27,8 @@ import dbus.service
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
call_async
-from mctest import exec_test, SimulatedConnection, create_fakecm_account
+from mctest import exec_test, SimulatedConnection, create_fakecm_account, \
+ make_mc
import constants as cs
cm_name_ref = dbus.service.BusName(
@@ -67,18 +68,25 @@ AvatarMime=image/jpeg
account_connections_file.write("")
account_connections_file.close()
-def test(q, bus, mc):
+def test(q, bus, unused):
+
expected_params = {
'account': 'jc.denton at unatco.int',
'password': 'ionstorm',
}
- e = q.expect('dbus-method-call', method='RequestConnection',
- args=['fakeprotocol', expected_params],
- destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
- path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
- interface=cs.tp_name_prefix + '.ConnectionManager',
- handled=False)
+ mc = make_mc(bus, q.append)
+
+ e, _ = q.expect_many(
+ EventPattern('dbus-method-call', method='RequestConnection',
+ args=['fakeprotocol', expected_params],
+ destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
+ path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
+ interface=cs.tp_name_prefix + '.ConnectionManager',
+ handled=False),
+ EventPattern('dbus-signal', signal='NameOwnerChanged',
+ predicate=lambda e: e.args[0] == cs.AM and e.args[2]),
+ )
conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
'myself', has_presence=True, has_aliasing=True, has_avatars=True)
@@ -133,4 +141,4 @@ def test(q, bus, mc):
if __name__ == '__main__':
preseed()
- exec_test(test, {})
+ exec_test(test, {}, preload_mc=False)
diff --git a/test/twisted/account-manager/avatar-persist.py b/test/twisted/account-manager/avatar-persist.py
index 3629ecd..fbb19ad 100644
--- a/test/twisted/account-manager/avatar-persist.py
+++ b/test/twisted/account-manager/avatar-persist.py
@@ -28,7 +28,8 @@ import dbus.service
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
call_async
-from mctest import exec_test, SimulatedConnection, create_fakecm_account
+from mctest import exec_test, SimulatedConnection, create_fakecm_account, \
+ make_mc
import constants as cs
cm_name_ref = dbus.service.BusName(
@@ -69,18 +70,25 @@ avatar_token=Deus Ex
account_connections_file.write("")
account_connections_file.close()
-def test(q, bus, mc):
+def test(q, bus, unused):
+
expected_params = {
'account': 'jc.denton at unatco.int',
'password': 'ionstorm',
}
- e = q.expect('dbus-method-call', method='RequestConnection',
- args=['fakeprotocol', expected_params],
- destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
- path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
- interface=cs.tp_name_prefix + '.ConnectionManager',
- handled=False)
+ mc = make_mc(bus, q.append)
+
+ e, _ = q.expect_many(
+ EventPattern('dbus-method-call', method='RequestConnection',
+ args=['fakeprotocol', expected_params],
+ destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
+ path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
+ interface=cs.tp_name_prefix + '.ConnectionManager',
+ handled=False),
+ EventPattern('dbus-signal', signal='NameOwnerChanged',
+ predicate=lambda e: e.args[0] == cs.AM and e.args[2]),
+ )
conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
'myself', has_avatars=True, avatars_persist=True)
@@ -139,4 +147,4 @@ def test(q, bus, mc):
if __name__ == '__main__':
preseed()
- exec_test(test, {})
+ exec_test(test, {}, preload_mc=False)
diff --git a/test/twisted/account-manager/avatar-refresh.py b/test/twisted/account-manager/avatar-refresh.py
index 00bd127..a356096 100644
--- a/test/twisted/account-manager/avatar-refresh.py
+++ b/test/twisted/account-manager/avatar-refresh.py
@@ -28,7 +28,8 @@ import dbus.service
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
call_async
-from mctest import exec_test, SimulatedConnection, create_fakecm_account
+from mctest import exec_test, SimulatedConnection, create_fakecm_account, \
+ make_mc
import constants as cs
cm_name_ref = dbus.service.BusName(
@@ -69,18 +70,25 @@ avatar_token=Deus Ex
account_connections_file.write("")
account_connections_file.close()
-def test(q, bus, mc):
+def test(q, bus, unused):
+
expected_params = {
'account': 'jc.denton at unatco.int',
'password': 'ionstorm',
}
- e = q.expect('dbus-method-call', method='RequestConnection',
- args=['fakeprotocol', expected_params],
- destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
- path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
- interface=cs.tp_name_prefix + '.ConnectionManager',
- handled=False)
+ mc = make_mc(bus, q.append)
+
+ e, _ = q.expect_many(
+ EventPattern('dbus-method-call', method='RequestConnection',
+ args=['fakeprotocol', expected_params],
+ destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
+ path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
+ interface=cs.tp_name_prefix + '.ConnectionManager',
+ handled=False),
+ EventPattern('dbus-signal', signal='NameOwnerChanged',
+ predicate=lambda e: e.args[0] == cs.AM and e.args[2]),
+ )
conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
'myself', has_avatars=True, avatars_persist=False)
@@ -120,4 +128,4 @@ def test(q, bus, mc):
if __name__ == '__main__':
preseed()
- exec_test(test, {})
+ exec_test(test, {}, preload_mc=False)
diff --git a/test/twisted/account-manager/make-valid.py b/test/twisted/account-manager/make-valid.py
index 7c07ae3..7da7902 100644
--- a/test/twisted/account-manager/make-valid.py
+++ b/test/twisted/account-manager/make-valid.py
@@ -233,4 +233,4 @@ def test(q, bus, unused):
if __name__ == '__main__':
preseed()
- exec_test(test, {})
+ exec_test(test, {}, preload_mc=False)
diff --git a/test/twisted/mctest.py b/test/twisted/mctest.py
index 5fd242c..26a3ef7 100644
--- a/test/twisted/mctest.py
+++ b/test/twisted/mctest.py
@@ -83,6 +83,18 @@ def exec_test_deferred (fun, params, protocol=None, timeout=None,
queue.attach_to_bus(bus)
if preload_mc:
mc = make_mc(bus, queue.append, params)
+
+ try:
+ bus.get_name_owner(cs.AM)
+ except dbus.DBusException, e:
+ queue.expect('dbus-signal', signal='NameOwnerChanged',
+ predicate=lambda e: e.args[0] == cs.AM and e.args[2])
+
+ try:
+ bus.get_name_owner(cs.CD)
+ except dbus.DBusException, e:
+ queue.expect('dbus-signal', signal='NameOwnerChanged',
+ predicate=lambda e: e.args[0] == cs.CD and e.args[2])
else:
mc = None
error = None
--
1.5.6.5
More information about the telepathy-commits
mailing list