|
@@ -221,11 +221,6 @@ class ComponentTests(BossUtils, unittest.TestCase):
|
|
|
"""
|
|
|
Check the component restarted successfully.
|
|
|
|
|
|
- Currently, it is implemented as starting it again right away. This will
|
|
|
- change, it will register itself into the restart schedule in boss. But
|
|
|
- as the integration with boss is not clear yet, we don't know how
|
|
|
- exactly that will happen.
|
|
|
-
|
|
|
Reset the self.__start_called to False before calling the function when
|
|
|
the component should fail.
|
|
|
"""
|
|
@@ -237,6 +232,16 @@ class ComponentTests(BossUtils, unittest.TestCase):
|
|
|
# Check it can't be started again
|
|
|
self.assertRaises(ValueError, component.start)
|
|
|
|
|
|
+ def __check_not_restarted(self, component):
|
|
|
+ """
|
|
|
+ Check the component has not (yet) restarted successfully.
|
|
|
+ """
|
|
|
+ self.assertFalse(self._shutdown)
|
|
|
+ self.assertTrue(self.__start_called)
|
|
|
+ self.assertFalse(self.__stop_called)
|
|
|
+ self.assertTrue(self.__failed_called)
|
|
|
+ self.assertFalse(component.running())
|
|
|
+
|
|
|
def __do_start_stop(self, kind):
|
|
|
"""
|
|
|
This is a body of a test. It creates a component of given kind,
|
|
@@ -296,7 +301,9 @@ class ComponentTests(BossUtils, unittest.TestCase):
|
|
|
component.start()
|
|
|
self.__check_started(component)
|
|
|
# Pretend the component died
|
|
|
- component.failed(1)
|
|
|
+ restarted = component.failed(1)
|
|
|
+ # Since it is a core component, it should not be restarted
|
|
|
+ self.assertFalse(restarted)
|
|
|
# It should bring down the whole server
|
|
|
self.__check_dead(component)
|
|
|
|
|
@@ -312,7 +319,9 @@ class ComponentTests(BossUtils, unittest.TestCase):
|
|
|
self.__check_started(component)
|
|
|
self._timeskip()
|
|
|
# Pretend the component died some time later
|
|
|
- component.failed(1)
|
|
|
+ restarted = component.failed(1)
|
|
|
+ # Should not be restarted
|
|
|
+ self.assertFalse(restarted)
|
|
|
# Check the component is still dead
|
|
|
self.__check_dead(component)
|
|
|
|
|
@@ -328,7 +337,9 @@ class ComponentTests(BossUtils, unittest.TestCase):
|
|
|
component.start()
|
|
|
self.__check_started(component)
|
|
|
# Make it fail right away.
|
|
|
- component.failed(1)
|
|
|
+ restarted = component.failed(1)
|
|
|
+ # Should not have restarted
|
|
|
+ self.assertFalse(restarted)
|
|
|
self.__check_dead(component)
|
|
|
|
|
|
def test_start_fail_needed_later(self):
|
|
@@ -344,37 +355,65 @@ class ComponentTests(BossUtils, unittest.TestCase):
|
|
|
# Make it fail later on
|
|
|
self.__start_called = False
|
|
|
self._timeskip()
|
|
|
- component.failed(1)
|
|
|
+ restarted = component.failed(1)
|
|
|
+ # Should have restarted
|
|
|
+ self.assertTrue(restarted)
|
|
|
self.__check_restarted(component)
|
|
|
|
|
|
def test_start_fail_dispensable(self):
|
|
|
"""
|
|
|
- Start and then fail a dispensable component. Should just get restarted.
|
|
|
+ Start and then fail a dispensable component. Should not get restarted.
|
|
|
"""
|
|
|
# Just ordinary startup
|
|
|
- component = self.__create_component('needed')
|
|
|
+ component = self.__create_component('dispensable')
|
|
|
self.__check_startup(component)
|
|
|
component.start()
|
|
|
self.__check_started(component)
|
|
|
# Make it fail right away
|
|
|
- self.__start_called = False
|
|
|
- component.failed(1)
|
|
|
- self.__check_restarted(component)
|
|
|
+ restarted = component.failed(1)
|
|
|
+ # Should signal that it did not restart
|
|
|
+ self.assertFalse(restarted)
|
|
|
+ self.__check_not_restarted(component)
|
|
|
|
|
|
- def test_start_fail_dispensable(self):
|
|
|
+ def test_start_fail_dispensable_later(self):
|
|
|
"""
|
|
|
Start and then later on fail a dispensable component. Should just get
|
|
|
restarted.
|
|
|
"""
|
|
|
# Just ordinary startup
|
|
|
- component = self.__create_component('needed')
|
|
|
+ component = self.__create_component('dispensable')
|
|
|
self.__check_startup(component)
|
|
|
component.start()
|
|
|
self.__check_started(component)
|
|
|
# Make it fail later on
|
|
|
- self.__start_called = False
|
|
|
self._timeskip()
|
|
|
- component.failed(1)
|
|
|
+ restarted = component.failed(1)
|
|
|
+ # should signal that it restarted
|
|
|
+ self.assertTrue(restarted)
|
|
|
+ # and check if it really did
|
|
|
+ self.__check_restarted(component)
|
|
|
+
|
|
|
+ def test_start_fail_dispensable_restart_later(self):
|
|
|
+ """
|
|
|
+ Start and then fail a dispensable component, wait a bit and try to
|
|
|
+ restart. Should get restarted after the wait.
|
|
|
+ """
|
|
|
+ # Just ordinary startup
|
|
|
+ component = self.__create_component('dispensable')
|
|
|
+ self.__check_startup(component)
|
|
|
+ component.start()
|
|
|
+ self.__check_started(component)
|
|
|
+ # Make it fail immediately
|
|
|
+ restarted = component.failed(1)
|
|
|
+ # should signal that it did not restart
|
|
|
+ self.assertFalse(restarted)
|
|
|
+ self.__check_not_restarted(component)
|
|
|
+ self._timeskip()
|
|
|
+ # try to restart again
|
|
|
+ restarted = component.restart()
|
|
|
+ # should signal that it restarted
|
|
|
+ self.assertTrue(restarted)
|
|
|
+ # and check if it really did
|
|
|
self.__check_restarted(component)
|
|
|
|
|
|
def test_fail_core(self):
|
|
@@ -402,14 +441,56 @@ class ComponentTests(BossUtils, unittest.TestCase):
|
|
|
def test_fail_dispensable(self):
|
|
|
"""
|
|
|
Failure to start a dispensable component. The exception should get
|
|
|
- through, but it should be restarted.
|
|
|
+ through, but it should be restarted after a time skip.
|
|
|
"""
|
|
|
component = self.__create_component('dispensable')
|
|
|
self.__check_startup(component)
|
|
|
component._start_internal = self.__fail_to_start
|
|
|
self.assertRaises(TestError, component.start)
|
|
|
+ # tell it to see if it must restart
|
|
|
+ restarted = component.restart()
|
|
|
+ # should not have restarted yet
|
|
|
+ self.assertFalse(restarted)
|
|
|
+ self.__check_not_restarted(component)
|
|
|
+ self._timeskip()
|
|
|
+ # tell it to see if it must restart and do so, with our vision of time
|
|
|
+ restarted = component.restart()
|
|
|
+ # should have restarted now
|
|
|
+ self.assertTrue(restarted)
|
|
|
+ self.__check_restarted(component)
|
|
|
+
|
|
|
+ def test_component_start_time(self):
|
|
|
+ """
|
|
|
+ Check that original start time is set initially, and remains the same
|
|
|
+ after a restart, while the internal __start_time does change
|
|
|
+ """
|
|
|
+ # Just ordinary startup
|
|
|
+ component = self.__create_component('dispensable')
|
|
|
+ self.__check_startup(component)
|
|
|
+ self.assertIsNone(component._original_start_time)
|
|
|
+ component.start()
|
|
|
+ self.__check_started(component)
|
|
|
+
|
|
|
+ self.assertIsNotNone(component._original_start_time)
|
|
|
+ self.assertIsNotNone(component._BaseComponent__start_time)
|
|
|
+ original_start_time = component._original_start_time
|
|
|
+ start_time = component._BaseComponent__start_time
|
|
|
+ # Not restarted yet, so they should be the same
|
|
|
+ self.assertEqual(original_start_time, start_time)
|
|
|
+
|
|
|
+ self._timeskip()
|
|
|
+ # Make it fail
|
|
|
+ restarted = component.failed(1)
|
|
|
+ # should signal that it restarted
|
|
|
+ self.assertTrue(restarted)
|
|
|
+ # and check if it really did
|
|
|
self.__check_restarted(component)
|
|
|
|
|
|
+ # original start time should not have changed
|
|
|
+ self.assertEqual(original_start_time, component._original_start_time)
|
|
|
+ # but actual start time should
|
|
|
+ self.assertNotEqual(start_time, component._BaseComponent__start_time)
|
|
|
+
|
|
|
def test_bad_kind(self):
|
|
|
"""
|
|
|
Test the component rejects nonsensical kinds. This includes bad
|