Changeset 169:bb939a909750
- Timestamp:
- Feb 25, 2012, 8:27:56 PM (10 years ago)
- Branch:
- default
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
NEWS
r167 r169 1 x.x.x (yyyy-mm-dd) 2 ================== 3 4 Fixes 5 ----- 6 7 - wokkel.component.Component now reconnects if first attempt failed (#75). 8 9 1 10 0.7.0 (2012-01-23) 2 ====================== 3 4 Features 5 -------- 11 ================== 12 13 Features 14 -------- 15 6 16 - Added method wokkel.data_form.Form.typeCheck for type checking incoming Data 7 17 Forms submissions against field definitions. -
wokkel/component.py
r166 r169 5 5 6 6 """ 7 XMPP External Component utilities 7 XMPP External Component utilities. 8 8 """ 9 9 … … 21 21 22 22 class Component(StreamManager, service.Service): 23 """ 24 XMPP External Component service. 25 26 This service is a XMPP stream manager that connects as an External 27 Component to an XMPP server, as described in 28 U{XEP-0114<http://xmpp.org/extensions/xep-0114.html>}. 29 """ 23 30 def __init__(self, host, port, jid, password): 24 31 self.host = host … … 29 36 StreamManager.__init__(self, factory) 30 37 38 31 39 def _authd(self, xs): 40 """ 41 Called when stream initialization has completed. 42 43 This replaces the C{send} method of the C{XmlStream} instance 44 that represents the current connection so that outgoing stanzas 45 always have a from attribute set to the JID of the component. 46 """ 32 47 old_send = xs.send 33 48 … … 41 56 StreamManager._authd(self, xs) 42 57 58 43 59 def initializationFailed(self, reason): 44 60 """ … … 51 67 reason.raiseException() 52 68 69 53 70 def startService(self): 71 """ 72 Start the service and connect to the server. 73 """ 54 74 service.Service.startService(self) 55 75 76 self._connection = self._getConnection() 77 78 79 def stopService(self): 80 """ 81 Stop the service, close the connection and prevent reconnects. 82 """ 83 service.Service.stopService(self) 84 56 85 self.factory.stopTrying() 57 self._connection = self._getConnection()58 59 def stopService(self):60 service.Service.stopService(self)61 62 86 self._connection.disconnect() 63 87 88 64 89 def _getConnection(self): 90 """ 91 Create a connector that connects to the server. 92 """ 65 93 return reactor.connectTCP(self.host, self.port, self.factory) 66 94 -
wokkel/test/test_component.py
r165 r169 3 3 4 4 """ 5 Tests for L{wokkel.component} 5 Tests for L{wokkel.component}. 6 6 """ 7 7 8 8 from zope.interface.verify import verifyObject 9 9 10 from twisted.internet.base import BaseConnector 11 from twisted.internet.error import ConnectionRefusedError 12 from twisted.internet.task import Clock 10 13 from twisted.python import failure 11 14 from twisted.trial import unittest … … 18 21 from wokkel import component 19 22 from wokkel.generic import XmlPipe 23 24 class FakeConnector(BaseConnector): 25 """ 26 Fake connector that counts connection attempts. 27 """ 28 connects = 0 29 30 def connect(self): 31 self.connects += 1 32 BaseConnector.connect(self) 33 34 35 def _makeTransport(self): 36 return None 37 38 39 40 class TestableComponent(component.Component): 41 """ 42 Testable component. 43 44 This component provides the created factory with a L{Clock} 45 instead of the regular reactor and uses L{FakeConnector} for testing 46 connects and reconnects. 47 """ 48 49 def __init__(self, *args, **kwargs): 50 component.Component.__init__(self, *args, **kwargs) 51 self.factory.clock = Clock() 52 53 54 def _getConnection(self): 55 c = FakeConnector(self.factory, None, None) 56 c.connect() 57 return c 58 59 60 61 class ComponentTest(unittest.TestCase): 62 """ 63 Tests for L{component.Component}. 64 """ 65 def test_startServiceReconnectAfterFailure(self): 66 """ 67 When the first connection attempt fails, retry. 68 """ 69 comp = TestableComponent('example.org', 5347, 70 'test.example.org', 'secret') 71 72 # Starting the service initiates a connection attempt. 73 comp.startService() 74 connector = comp._connection 75 self.assertEqual(1, connector.connects) 76 77 # Fail the connection. 78 connector.connectionFailed(ConnectionRefusedError()) 79 80 # After a back-off delay, a new connection is attempted. 81 comp.factory.clock.advance(5) 82 self.assertEqual(2, connector.connects) 83 84 85 def test_stopServiceNoReconnect(self): 86 """ 87 When the service is stopped, no reconnect is attempted. 88 """ 89 comp = TestableComponent('example.org', 5347, 90 'test.example.org', 'secret') 91 92 # Starting the service initiates a connection attempt. 93 comp.startService() 94 connector = comp._connection 95 96 # Fail the connection. 97 connector.connectionFailed(ConnectionRefusedError()) 98 99 # If the service is stopped before the back-off delay expires, 100 # no new connection is attempted. 101 comp.factory.clock.advance(1) 102 comp.stopService() 103 comp.factory.clock.advance(4) 104 self.assertEqual(1, connector.connects) 105 106 20 107 21 108 class InternalComponentTest(unittest.TestCase):
Note: See TracChangeset
for help on using the changeset viewer.