Skip to content

Commit

Permalink
Merge branch 'develop' into feature/issue-1017-add-event-exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Nov 23, 2015
2 parents e41af2b + 2523b60 commit ce2ea2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions vumi/transports/xmpp/tests/test_xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from twisted.words.xish import domish

from vumi.tests.helpers import VumiTestCase
from vumi.tests.utils import LogCatcher
from vumi.transports.xmpp.xmpp import (
XMPPTransport, XMPPClient, XMPPTransportProtocol)
from vumi.transports.tests.helpers import TransportHelper
Expand Down Expand Up @@ -197,3 +198,16 @@ def test_normalizing_from_addr(self):
[msg] = yield self.tx_helper.wait_for_dispatched_inbound()
self.assertEqual(msg['from_addr'], 'test@case.com')
self.assertEqual(msg['transport_metadata']['xmpp_id'], message['id'])

@inlineCallbacks
def test_xmpp_connection_lost(self):
'''When the XMPP connection is lost, the connection callback should
be called, which should log that the connection was lost.'''
transport = yield self.mk_transport()

with LogCatcher() as lc:
yield transport.xmpp_protocol.connectionLost('Test connection')

[log] = lc.logs
self.assertEqual(
log['log_text'], 'XMPP Connection lost. Test connection')
7 changes: 5 additions & 2 deletions vumi/transports/xmpp/xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def connectionMade(self):
def connectionLost(self, reason):
if self.connection_lost_callback is not None:
self.connection_lost_callback(reason)
self.log.msg("XMPP Connection lost.")
super(XMPPTransportProtocol, self).connectionLost(reason)


Expand Down Expand Up @@ -170,11 +169,15 @@ def setup_transport(self):
roster.setHandlerParent(self.xmpp_client)

self.xmpp_protocol = self._xmpp_protocol(
self.jid, self.publish_message, self.unpause_connectors)
self.jid, self.publish_message, self.unpause_connectors,
connection_lost_callback=self.connection_lost)
self.xmpp_protocol.setHandlerParent(self.xmpp_client)

self.log.msg("XMPPTransport %s started." % self.transport_name)

def connection_lost(self, reason):
self.log.msg("XMPP Connection lost. %s" % reason)

def announce_presence(self):
if not self.presence_call.running:
self.presence_call.start(self.presence_interval)
Expand Down

0 comments on commit ce2ea2a

Please sign in to comment.