Restart when Jabber server close the connection
darcs-hash:20080821200041-86b55-3564edeb58a6582efd4325c938ae7a9315921082.gz
This commit is contained in:
@@ -673,6 +673,7 @@ class JCLComponent(Component, object):
|
|||||||
timer_thread = threading.Thread(target=self.time_handler,
|
timer_thread = threading.Thread(target=self.time_handler,
|
||||||
name="TimerThread")
|
name="TimerThread")
|
||||||
timer_thread.start()
|
timer_thread.start()
|
||||||
|
wait_before_restart = 0
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
while (self.running and self.stream
|
while (self.running and self.stream
|
||||||
@@ -685,6 +686,9 @@ class JCLComponent(Component, object):
|
|||||||
self.__logger.info("Connection failed, restarting.")
|
self.__logger.info("Connection failed, restarting.")
|
||||||
return (True, 5)
|
return (True, 5)
|
||||||
finally:
|
finally:
|
||||||
|
if self.running:
|
||||||
|
self._restart = True
|
||||||
|
wait_before_restart = 5
|
||||||
self.running = False
|
self.running = False
|
||||||
timer_thread.join(JCLComponent.timeout)
|
timer_thread.join(JCLComponent.timeout)
|
||||||
self.wait_event.set()
|
self.wait_event.set()
|
||||||
@@ -694,7 +698,7 @@ class JCLComponent(Component, object):
|
|||||||
self.send_stanzas(presences)
|
self.send_stanzas(presences)
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
self.__logger.debug("Exitting normally")
|
self.__logger.debug("Exitting normally")
|
||||||
return (self._restart, 0)
|
return (self._restart, wait_before_restart)
|
||||||
|
|
||||||
def _get_restart(self):
|
def _get_restart(self):
|
||||||
return self._restart
|
return self._restart
|
||||||
|
|||||||
@@ -2967,7 +2967,7 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
|||||||
raise self.comp.queue.get(0)
|
raise self.comp.queue.get(0)
|
||||||
|
|
||||||
def test_run_connection_failed(self):
|
def test_run_connection_failed(self):
|
||||||
"""Test when connection to Jabber server failed"""
|
"""Test when connection to Jabber server fails"""
|
||||||
class MockStreamLoopFailed(MockStream):
|
class MockStreamLoopFailed(MockStream):
|
||||||
def connect(self):
|
def connect(self):
|
||||||
self.connection_started = True
|
self.connection_started = True
|
||||||
@@ -2988,6 +2988,26 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase):
|
|||||||
self.assertEquals(len(threads), 1)
|
self.assertEquals(len(threads), 1)
|
||||||
self.assertFalse(self.comp.stream.connection_stopped)
|
self.assertFalse(self.comp.stream.connection_stopped)
|
||||||
|
|
||||||
|
def test_run_connection_closed(self):
|
||||||
|
"""Test when connection to Jabber server is closed"""
|
||||||
|
def do_nothing():
|
||||||
|
self.comp.stream.eof = True
|
||||||
|
return
|
||||||
|
self.comp.handle_tick = do_nothing
|
||||||
|
self.comp.time_unit = 1
|
||||||
|
# Do not loop, handle_tick is virtual
|
||||||
|
self.comp.stream = MockStreamNoConnect()
|
||||||
|
self.comp.stream_class = MockStreamNoConnect
|
||||||
|
self.comp.restart = False
|
||||||
|
(result, time_to_wait) = self.comp.run()
|
||||||
|
self.assertEquals(time_to_wait, 5)
|
||||||
|
self.assertTrue(result)
|
||||||
|
self.assertFalse(self.comp.running)
|
||||||
|
self.assertTrue(self.comp.stream.connection_started)
|
||||||
|
threads = threading.enumerate()
|
||||||
|
self.assertEquals(len(threads), 1)
|
||||||
|
self.assertFalse(self.comp.stream.connection_stopped)
|
||||||
|
|
||||||
def test_run_unhandled_error(self):
|
def test_run_unhandled_error(self):
|
||||||
"""Test main loop unhandled error from a component handler"""
|
"""Test main loop unhandled error from a component handler"""
|
||||||
def do_nothing():
|
def do_nothing():
|
||||||
|
|||||||
Reference in New Issue
Block a user