summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-10-30 15:52:09 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2012-10-30 16:02:57 +0000
commiteb437c2f0bbc7061570889a825b131969982cc9a (patch)
tree55ac4034da4d112c06cf2376bf358a1c8e48cdf2 /tests
parent5fc2d07d025fca9a19abd09caa8b7de2ab8911ed (diff)
Connection: disconnect if we get no PONG for our PING
Previously we'd just send out a PING into the æther every n seconds, and pay no attention to whether we ever got an answer. So it was perfectly possible for the connection to just sit there until the TCP timeout kicks in, which I think is a matter of hours by default. With this patch, if we haven't heard a PONG 3 keepalive-intervals after sending a PING, Idle throws its toys out of the pram. This has been tested as follows: * Put my laptop on a wired and wireless network simultaneously. * Connect to an IRC server. (The wired network is used.) * Pull the network cable out. Idle is too stupid to realise the link it was using is gone, and because we're still ostensibly online, nothing tells it to disconnect. * Wait keepalive-interval * 4, and watch the connection get disconnected. It works both with a direct connection to Freenode, and with a connection over an SSH tunnel to irssi-proxy.
Diffstat (limited to 'tests')
-rw-r--r--tests/twisted/connect/ping.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/tests/twisted/connect/ping.py b/tests/twisted/connect/ping.py
index 7d77341..9c1f6ca 100644
--- a/tests/twisted/connect/ping.py
+++ b/tests/twisted/connect/ping.py
@@ -1,9 +1,10 @@
"""
-Test Idle sending PINGs.
+Test Idle sending PINGs and timing out if it doesn't get a reply.
"""
from idletest import exec_test
-from servicetest import assertLength
+from servicetest import assertLength, EventPattern
+import constants as cs
def test(q, bus, conn, stream):
conn.Connect()
@@ -15,8 +16,20 @@ def test(q, bus, conn, stream):
stream.sendMessage('PONG', 'idle.test.server', ':%s' % timestamp,
prefix='idle.test.server')
+ q.expect('stream-PING')
+ # If we don't answer Idle's ping, after some period of time Idle should
+ # give up and close the connection.
+ q.expect_many(
+ EventPattern('irc-disconnected'),
+ EventPattern('dbus-signal', signal='StatusChanged',
+ args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_NETWORK_ERROR]),
+ )
+
if __name__ == '__main__':
- exec_test(test, params={
+ # We expect Idle to blow up the connection after three intervals without a
+ # reply. So the default 5-second test timeout *should* just be enough, but
+ # let's not risk it.
+ exec_test(test, timeout=10, params={
'keepalive-interval': 1,
})