Browse Source

[2856] Raise an exception if start_update() is called in any state other than READY

Mukund Sivaraman 12 years ago
parent
commit
4f96d3ab2e

+ 8 - 4
src/lib/python/isc/memmgr/datasrc_info.py

@@ -144,11 +144,15 @@ class SegmentInfo:
         event (without removing it from the pending events queue). This
         tells the caller (memmgr) that it should initiate the update
         process with the builder. In all other cases it returns None."""
-        if self.__state == self.READY and self.__events:
-            self.__state = self.UPDATING
-            return self.__events[0]
+        if self.__state == self.READY:
+            if self.__events:
+                self.__state = self.UPDATING
+                return self.__events[0]
+            else:
+                return None
 
-        return None
+        raise SegmentInfoError('start_update() called in ' +
+                               'incorrect state: ' + str(self.__state))
 
     def complete_update(self):
         """This method should be called when memmgr is notified by the

+ 8 - 11
src/lib/python/isc/memmgr/tests/datasrc_info_tests.py

@@ -134,25 +134,22 @@ class TestSegmentInfo(unittest.TestCase):
         self.assertTupleEqual(e, (42,))
         self.assertEqual(self.__sgmt_info.get_state(), SegmentInfo.UPDATING)
 
-        # in UPDATING state, it should always return None and not change
-        # state.
+        # in UPDATING state, it should always raise an exception and not
+        # change state.
         self.__si_to_updating_state()
-        e = self.__sgmt_info.start_update()
-        self.assertIsNone(e)
+        self.assertRaises(SegmentInfoError, self.__sgmt_info.start_update)
         self.assertEqual(self.__sgmt_info.get_state(), SegmentInfo.UPDATING)
 
-        # in SYNCHRONIZING state, it should always return None and not
-        # change state.
+        # in SYNCHRONIZING state, it should always raise an exception
+        # and not change state.
         self.__si_to_synchronizing_state()
-        e = self.__sgmt_info.start_update()
-        self.assertIsNone(e)
+        self.assertRaises(SegmentInfoError, self.__sgmt_info.start_update)
         self.assertEqual(self.__sgmt_info.get_state(), SegmentInfo.SYNCHRONIZING)
 
-        # in COPYING state, it should always return None and not
+        # in COPYING state, it should always raise an exception and not
         # change state.
         self.__si_to_copying_state()
-        e = self.__sgmt_info.start_update()
-        self.assertIsNone(e)
+        self.assertRaises(SegmentInfoError, self.__sgmt_info.start_update)
         self.assertEqual(self.__sgmt_info.get_state(), SegmentInfo.COPYING)
 
     def test_complete_update(self):