From 6d197ed30d0f4fb17d316be966206782cbbfe1e3 Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Thu, 29 Jan 2009 12:24:27 -0600 Subject: Speed up the tests a bit When I was figuring out the test framework and trying to get things to work, I had bumped up the time out on a bunch of tests to 10s rather than the default 5. This means that a timeout failure takes a lot longer to happen and there's really no need for a full 10s timeout. Also, when testing that messages are sent in the right order, there's no need to send 10 messages, so cut a few of them. Since there's a built-in 2s delay between each sent message, that means the test was always taking *at least* 20s to execute. --- tests/twisted/channels/join-muc-channel.py | 2 +- tests/twisted/connect/connect-success-ssl.py | 2 +- tests/twisted/connect/connect-success.py | 2 +- tests/twisted/messages/leading-space.py | 2 +- tests/twisted/messages/message-order.py | 12 +----------- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/twisted/channels/join-muc-channel.py b/tests/twisted/channels/join-muc-channel.py index 126b59c..7e2e73b 100644 --- a/tests/twisted/channels/join-muc-channel.py +++ b/tests/twisted/channels/join-muc-channel.py @@ -36,5 +36,5 @@ def test(q, bus, conn, stream): return True if __name__ == '__main__': - exec_test(test, timeout=10) + exec_test(test) diff --git a/tests/twisted/connect/connect-success-ssl.py b/tests/twisted/connect/connect-success-ssl.py index 3cf04e8..627eeb8 100644 --- a/tests/twisted/connect/connect-success-ssl.py +++ b/tests/twisted/connect/connect-success-ssl.py @@ -23,5 +23,5 @@ def test(q, bus, conn, stream): return True if __name__ == '__main__': - exec_test(test, {'use-ssl':dbus.Boolean(True)}, protocol=SSLIRCServer, timeout=10) + exec_test(test, {'use-ssl':dbus.Boolean(True)}, protocol=SSLIRCServer) diff --git a/tests/twisted/connect/connect-success.py b/tests/twisted/connect/connect-success.py index 9ef189b..3281764 100644 --- a/tests/twisted/connect/connect-success.py +++ b/tests/twisted/connect/connect-success.py @@ -22,5 +22,5 @@ def test(q, bus, conn, stream): return True if __name__ == '__main__': - exec_test(test, timeout=10) + exec_test(test) diff --git a/tests/twisted/messages/leading-space.py b/tests/twisted/messages/leading-space.py index a621993..ce24c76 100644 --- a/tests/twisted/messages/leading-space.py +++ b/tests/twisted/messages/leading-space.py @@ -51,5 +51,5 @@ def test(q, bus, conn, stream): return True if __name__ == '__main__': - exec_test(test, timeout=10, protocol=LeadingSpaceIRCServer) + exec_test(test, protocol=LeadingSpaceIRCServer) diff --git a/tests/twisted/messages/message-order.py b/tests/twisted/messages/message-order.py index 68dfd11..b2259ca 100644 --- a/tests/twisted/messages/message-order.py +++ b/tests/twisted/messages/message-order.py @@ -28,26 +28,16 @@ def test(q, bus, conn, stream): call_async(q, text_chan, 'Send', 0, '2') call_async(q, text_chan, 'Send', 0, '3') call_async(q, text_chan, 'Send', 0, '4') - call_async(q, text_chan, 'Send', 0, '5') - call_async(q, text_chan, 'Send', 0, '6') - call_async(q, text_chan, 'Send', 0, '7') - call_async(q, text_chan, 'Send', 0, '8') - call_async(q, text_chan, 'Send', 0, '9') q.expect('irc-privmsg', data={'message':'0','recipient':CHANNEL_NAME}) q.expect('irc-privmsg', data={'message':'1','recipient':CHANNEL_NAME}) q.expect('irc-privmsg', data={'message':'2','recipient':CHANNEL_NAME}) q.expect('irc-privmsg', data={'message':'3','recipient':CHANNEL_NAME}) q.expect('irc-privmsg', data={'message':'4','recipient':CHANNEL_NAME}) - q.expect('irc-privmsg', data={'message':'5','recipient':CHANNEL_NAME}) - q.expect('irc-privmsg', data={'message':'6','recipient':CHANNEL_NAME}) - q.expect('irc-privmsg', data={'message':'7','recipient':CHANNEL_NAME}) - q.expect('irc-privmsg', data={'message':'8','recipient':CHANNEL_NAME}) - q.expect('irc-privmsg', data={'message':'9','recipient':CHANNEL_NAME}) call_async(q, conn, 'Disconnect') return True if __name__ == '__main__': - exec_test(test, timeout=10) + exec_test(test) -- cgit v1.2.3 From 919ee9b1448430737f89056209280947ec5ade72 Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Tue, 27 Jan 2009 17:23:12 -0600 Subject: Add test for Bug #19766: private messages deliver to group chat This test currently fails because the user joins a channel with the same name as the user, and when a remote contact sends a private message to the user it gets signalled as 'Received' on both the private chat channel and the group chat channel --- tests/twisted/Makefile.am | 1 + tests/twisted/messages/room-contact-mixup.py | 87 ++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/twisted/messages/room-contact-mixup.py diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 7b1d3b0..be7062e 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -6,6 +6,7 @@ TWISTED_TESTS = \ channels/join-muc-channel.py \ messages/message-order.py \ messages/leading-space.py \ + messages/room-contact-mixup.py \ $(NULL) TESTS = diff --git a/tests/twisted/messages/room-contact-mixup.py b/tests/twisted/messages/room-contact-mixup.py new file mode 100644 index 0000000..ada469e --- /dev/null +++ b/tests/twisted/messages/room-contact-mixup.py @@ -0,0 +1,87 @@ + +""" +Regression test for a bug where, if you were in a IRC channel that had the same +name as your nickname (e.g. user 'foo' in room '#foo'), all private 1:1 messages +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 +import dbus + + +HANDLE_TYPE_CONTACT=1 +HANDLE_TYPE_ROOM=2 + +# same nick and channel +CHANNEL = '#foo' +NICK = 'foo' +REMOTEUSER = 'remoteuser' + +class CustomIRCServer(BaseIRCServer): + + def handlePRIVMSG(self, args, prefix): + #chain up to the base class implementation which simply signals a privmsg event + BaseIRCServer.handlePRIVMSG(self, args, prefix) + sender = prefix + recipient = args[0] + if (recipient == REMOTEUSER): + # auto-reply with a private message + self.sendMessage('PRIVMSG', self.nick, ':PRIVATE', prefix=REMOTEUSER) + elif (recipient == self.room): + # auto-reply to the group + self.sendMessage('PRIVMSG', self.room, ':GROUP', prefix=REMOTEUSER) + + def handleJOIN(self, args, prefix): + self.room = args[0] + self.sendMessage('JOIN', self.room, prefix=self.nick) + self._sendNameReply(self.room, [self.nick, REMOTEUSER]) + +def test(q, bus, conn, stream): + conn.Connect() + q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) + + # join a chat room with the same name as our nick + room_handles = conn.RequestHandles(HANDLE_TYPE_ROOM, [CHANNEL]) + call_async(q, conn, 'RequestChannel', + 'org.freedesktop.Telepathy.Channel.Type.Text', HANDLE_TYPE_ROOM, + room_handles[0], True) + # wait for the join to finish + ret = q.expect('dbus-return', method='RequestChannel') + q.expect('dbus-signal', signal='MembersChanged') + + # now request a private chat channel with the remote contact + contact_handles = conn.RequestHandles(HANDLE_TYPE_CONTACT, [REMOTEUSER]) + chan_path = conn.RequestChannel('org.freedesktop.Telepathy.Channel.Type.Text', + HANDLE_TYPE_CONTACT, contact_handles[0], True) + chan = bus.get_object(conn.bus_name, chan_path) + priv_text_chan = dbus.Interface(chan, + u'org.freedesktop.Telepathy.Channel.Type.Text') + + # send a private chat message -- the test server is rigged to send a private + # 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 + + call_async(q, conn, 'Disconnect') + return True + +if __name__ == '__main__': + exec_test(test, {'account':NICK}, protocol=CustomIRCServer) + -- cgit v1.2.3 From a88b5955d95ba5ed1fa7cd23b574883c5a017543 Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Tue, 27 Jan 2009 17:24:59 -0600 Subject: Fix Bug #19766: private messages no longer delivered to group chat This could perhaps be a slightly controversial change. The reason that the bug happened was that telepathy-idle's room handle repository normalizer function had some special code to make joining chatrooms more user-friendly. Basically, if the user specified a chatroom 'foo', it would assume you meant '#foo' and automatically prepend the '#' character. The way the parser currently works is that when we get in a privmsg, we try to parse the 'destination' of the privmsg as both a contact and a room. The way we determine if it's a valid room or not is by calling tp_handle_ensure(room_repo, ...) (and same for determining valid contacts). Unfortunately, because of the automatic #-prepending this means that a single privmsg destination can be both a valid contact and a valid channel name, so if the user is in a channel with the same name as their nick (but without the leading #), the privmsg will be handled by both the IMFactory and the MUCFactory --- src/idle-handles.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/idle-handles.c b/src/idle-handles.c index 2dd9ea3..d89b32a 100644 --- a/src/idle-handles.c +++ b/src/idle-handles.c @@ -121,12 +121,6 @@ static gchar *_nick_normalize_func(TpHandleRepoIface *repo, const gchar *id, gpo static gchar *_channel_normalize_func(TpHandleRepoIface *repo, const gchar *id, gpointer ctx, GError **error) { gchar *channel = g_strdup(id); - if ((channel[0] != '#') && (channel[0] != '!') && (channel[0] != '&') && (channel[0] != '+')) { - gchar *tmp = channel; - channel = g_strdup_printf("#%s", channel); - g_free(tmp); - } - if (!_channelname_is_valid(channel)) { g_set_error(error, TP_ERRORS, TP_ERROR_INVALID_HANDLE, "invalid channel ID"); return NULL; -- cgit v1.2.3 From d471f42675222cce620a219b36791e7f0e69bb5f Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Wed, 28 Jan 2009 11:27:19 -0600 Subject: Re-work the room-contact-mixup test with alban's suggestions 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 file 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 -- cgit v1.2.3