summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2010-12-01 00:42:23 (GMT)
committerWill Thompson <will.thompson@collabora.co.uk>2010-12-01 00:44:07 (GMT)
commitb6ed2b82ea285661d89c732dffc83825bd118938 (patch)
treedb937d143ad1f7c51a3c3e015834152fb533427c
parentfd2749f45339b0d7d0c308d693f5775d50242cbf (diff)
downloadtelepathy-idle-spam.tar.gz
telepathy-idle-spam.tar.xz
Add a test simulating a channel with a spammer.spam
I had hoped that this would catch <https://bugs.freedesktop.org/show_bug.cgi?id=29103> but it didn't. Seems like a reasonably useful thing to have kicking around though.
-rw-r--r--tests/twisted/Makefile.am3
-rw-r--r--tests/twisted/messages/spam.py81
2 files changed, 84 insertions, 0 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index a55e9b3..617f7a2 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -42,11 +42,14 @@ check-twisted:
endif
+# messages/spam takes forever, produces 5.9M of data, and doesn't actually
+# expose any bugs, so I'm not about to add it to the standard test suite.
EXTRA_DIST = \
$(TWISTED_TESTS) \
servicetest.py \
idletest.py \
constants.py \
+ messages/spam.py \
$(NULL)
CLEANFILES = idle-[1-9]*.log *.pyc */*.pyc
diff --git a/tests/twisted/messages/spam.py b/tests/twisted/messages/spam.py
new file mode 100644
index 0000000..2b83b8f
--- /dev/null
+++ b/tests/twisted/messages/spam.py
@@ -0,0 +1,81 @@
+"""
+Simulates a spammer!
+"""
+
+import random
+
+from idletest import exec_test
+from servicetest import EventPattern, call_async
+import constants as cs
+import dbus
+
+def generate_joins_and_parts():
+ """
+ This generator produces an infinite stream of tuples. The first element is
+ either JOIN or PART; the second is the nick doing the joining or parting.
+ The intention is to simulate a busyish channel.
+ """
+ names = ['Abel', 'Kenan', 'Enoch', 'Noah', 'Eber', 'Abraham', 'Isaac',
+ 'Jacob', 'Joseph', 'Sarah', 'Rebecca', 'Rachel', 'Leah', 'Moses',
+ 'Aaron', 'Miriam', 'Eldad', 'Phinehas', 'Joshua',
+ 'Deborah', 'Eli', 'Elkanah', 'Hannah', 'Abigail', 'Samuel', 'Gad',
+ 'Nathan', 'David', 'Solomon', 'Jeduthun', 'Ahiyah', 'Elijah',
+ 'Elisha', 'Shemaiah', 'Iddo', 'Azariah', 'Hanani', 'Jehu',
+ 'Micaiah', 'Jahaziel', 'Eliezer', 'Oded',
+ 'Huldah', 'Uriah', 'Hilkiah', 'Isaiah', 'Jeremiah', 'Ezekiel',
+ 'Daniel', 'Hosea', 'Joel', 'Amos', 'Obadiah', 'Jonah', 'Micah',
+ 'Nahum', 'Habakkuk', 'Zephaniah', 'Haggai', 'Zechariah', 'Malachi',
+ 'Beor', 'Balaam', 'Job', 'Eliphaz', 'Bildad', 'Zophar', 'Elihu',
+ 'Amoz', 'Beeri', 'Baruch', 'Buzi', 'Mordecai', 'Esther',
+ ]
+
+ while True:
+ for name in names:
+ yield ("JOIN", name)
+ for name in names:
+ yield ("PART", name)
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ q.expect('dbus-signal', signal='StatusChanged',
+ args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
+
+ call_async(q, conn.Requests, 'CreateChannel', {
+ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
+ cs.TARGET_HANDLE_TYPE: cs.HT_ROOM,
+ cs.TARGET_ID: '#test',
+ })
+ ret = q.expect('dbus-return')
+ path, _ = ret.value
+
+ q.expect('dbus-signal', signal='MembersChanged')
+ chan = bus.get_object(conn.bus_name, path)
+
+ join_and_part_stream = generate_joins_and_parts()
+
+ # Oh no! A spammer joins the channel and sends an offensive message
+ # incredibly frequently. The UI can't keep up, and only acks each batch of
+ # 100 messages after another 100 have already been received.
+ batch_a = []
+ batch_b = []
+ for j in range(0, 20):
+ for i in range(0, 100):
+ stream.sendMessage('PRIVMSG', '#test', ":I love horses",
+ prefix='b3ta')
+ event = q.expect('dbus-signal', interface=cs.CHANNEL_IFACE_MESSAGES,
+ signal='MessageReceived')
+ message, = event.args
+ batch_b.append(message[0]['pending-message-id'])
+
+ action, nick = join_and_part_stream.next()
+ stream.sendMessage(action, '#test', prefix=nick)
+ q.expect('dbus-signal', signal='MembersChanged')
+
+ random.shuffle(batch_a)
+ chan.AcknowledgePendingMessages(batch_a,
+ dbus_interface=cs.CHANNEL_TYPE_TEXT)
+ batch_a = batch_b
+ batch_b = []
+
+if __name__ == '__main__':
+ exec_test(test)