From d95702a9402b2fca25b66efb1a3770b19c6da0d1 Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Thu, 21 Aug 2008 22:40:12 +0200 Subject: [PATCH] Restart by default darcs-hash:20080821204012-86b55-4d943df45b93edc83b4177a9a8fdb1ec85af9fc6.gz --- src/jcl/jabber/component.py | 12 +++++++----- src/jcl/jabber/tests/component.py | 7 +++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/jcl/jabber/component.py b/src/jcl/jabber/component.py index a8ecd76..ba95998 100644 --- a/src/jcl/jabber/component.py +++ b/src/jcl/jabber/component.py @@ -673,7 +673,8 @@ class JCLComponent(Component, object): timer_thread = threading.Thread(target=self.time_handler, name="TimerThread") timer_thread.start() - wait_before_restart = 0 + wait_before_restart = 5 + self._restart = True try: try: while (self.running and self.stream @@ -686,10 +687,11 @@ class JCLComponent(Component, object): self.__logger.info("Connection failed, restarting.") return (True, 5) finally: - if self.running: - self._restart = True - wait_before_restart = 5 - self.running = False + if not self.running: + self._restart = False + wait_before_restart = 0 + else: + self.running = False timer_thread.join(JCLComponent.timeout) self.wait_event.set() if self.stream and not self.stream.eof \ diff --git a/src/jcl/jabber/tests/component.py b/src/jcl/jabber/tests/component.py index c199968..150afb6 100644 --- a/src/jcl/jabber/tests/component.py +++ b/src/jcl/jabber/tests/component.py @@ -2952,7 +2952,7 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase): def test_run_restart(self): """Test main loop execution with restart""" def do_nothing(): - self.comp.running = False + self.comp.stream.eof = True return self.comp.handle_tick = do_nothing self.comp.time_unit = 1 @@ -2961,12 +2961,11 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase): self.comp.stream_class = MockStreamNoConnect self.comp.restart = True (result, time_to_wait) = self.comp.run() - self.assertEquals(time_to_wait, 0) + self.assertEquals(time_to_wait, 5) self.assertTrue(result) self.assertTrue(self.comp.stream.connection_started) threads = threading.enumerate() self.assertEquals(len(threads), 1) - self.assertTrue(self.comp.stream.connection_stopped) if self.comp.queue.qsize(): raise self.comp.queue.get(0) @@ -3012,7 +3011,7 @@ class JCLComponent_run_TestCase(JCLComponent_TestCase): self.assertEquals(len(threads), 1) self.assertFalse(self.comp.stream.connection_stopped) - def test_run_unhandled_error(self): + def test_run_unhandled_error(self): # TODO : why it works ? """Test main loop unhandled error from a component handler""" def do_nothing(): return