[Telepathy-commits] [telepathy-idle/master] Re-work the room-contact-mixup test with alban's suggestions

Jonathon Jongsma jonathon.jongsma at collabora.co.uk
Fri Feb 13 17:43:18 PST 2009


use a signal handler on the dbus signal to set a global flag and assert that the
flag is false at the end rather than waiting for a signal we don't want to get.
I tested that this still failed without the patch and passes after, and it makes
the test a bit cleaner (and runs faster).
---
 tests/twisted/messages/room-contact-mixup.py |   35 +++++++++++++------------
 1 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/tests/twisted/messages/room-contact-mixup.py b/tests/twisted/messages/room-contact-mixup.py
index ada469e..dfd116f 100644
--- a/tests/twisted/messages/room-contact-mixup.py
+++ b/tests/twisted/messages/room-contact-mixup.py
@@ -6,7 +6,7 @@ to foo would appear to also be coming through room #foo as well (bug #19766)
 """
 
 from idletest import exec_test, BaseIRCServer
-from servicetest import EventPattern, call_async, TimeoutError
+from servicetest import EventPattern, call_async, TimeoutError, sync_dbus
 import dbus
 
 
@@ -37,6 +37,11 @@ class CustomIRCServer(BaseIRCServer):
         self.sendMessage('JOIN', self.room, prefix=self.nick)
         self._sendNameReply(self.room, [self.nick, REMOTEUSER])
 
+group_received_flag = False;
+def group_received_cb(id, timestamp, sender, type, flags, text):
+    global group_received_flag
+    group_received_flag = True
+
 def test(q, bus, conn, stream):
     conn.Connect()
     q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
@@ -48,6 +53,10 @@ def test(q, bus, conn, stream):
             room_handles[0], True)
     # wait for the join to finish
     ret = q.expect('dbus-return', method='RequestChannel')
+    chan = bus.get_object(conn.bus_name, ret.value[0])
+    group_text_chan = dbus.Interface(chan,
+            u'org.freedesktop.Telepathy.Channel.Type.Text')
+    group_text_chan.connect_to_signal('Received', group_received_cb)
     q.expect('dbus-signal', signal='MembersChanged')
 
     # now request a private chat channel with the remote contact
@@ -62,22 +71,14 @@ def test(q, bus, conn, stream):
     # chat response
     call_async(q, priv_text_chan, 'Send', 0, 'foo')
     q.expect('irc-privmsg', data={'message': 'foo', 'recipient': REMOTEUSER})
-    # the test server above is rigged to send a reply message with a leading
-    # space in response to our PRIVMSG.  If telepathy-idle parses this message
-    # correctly, we should emit a 'Received' signal
-    event = q.expect('dbus-signal', signal='Received', predicate=lambda x: x.args[5]=='PRIVATE')
-    if 'MucChannel' in event.path:
-        raise RuntimeError('PRIVATE message received on group chat interface')
-    else:
-        # maybe the ImChannel 'Received' signal arrived first and a MucChannel
-        # signal is still coming -- let's make sure it's not
-        try:
-            event = q.expect('dbus-signal', signal='Received', predicate=lambda x: x.args[5]=='PRIVATE')
-            if 'MucChannel' in event.path:
-                raise RuntimeError('PRIVATE message received on group chat interface')
-        except TimeoutError:
-            #ignore it -- we *want* this to time out
-            pass
+    event = q.expect('dbus-signal', signal='Received',
+            predicate=lambda x: x.args[5]=='PRIVATE' and 'ImChannel' in x.path)
+
+    # verify that we didn't receive a 'Received' D-Bus signal on the group text
+    # channel
+    global group_received_flag
+    sync_dbus(bus, q, conn)
+    assert group_received_flag == False
 
     call_async(q, conn, 'Disconnect')
     return True
-- 
1.5.6.5



More information about the telepathy-commits mailing list