From bda928cf714c45a6bbb0f29238f9b8d2897c0919 Mon Sep 17 00:00:00 2001 From: Diego Tavares Date: Wed, 11 Dec 2024 15:26:17 -0800 Subject: [PATCH] Fix unit tests and add core counting to recovery logic --- rqd/rqd/rqcore.py | 6 ++++++ rqd/tests/rqcore_test.py | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/rqd/rqd/rqcore.py b/rqd/rqd/rqcore.py index b2a2edff8..08c7444e9 100644 --- a/rqd/rqd/rqcore.py +++ b/rqd/rqd/rqcore.py @@ -237,6 +237,12 @@ def recoverCache(self): running_frame = rqd.rqnetwork.RunningFrame(self, run_frame) running_frame.frameAttendantThread = FrameAttendantThread( self, run_frame, running_frame, recovery_mode=True) + # Make sure cores are accounted for + # pylint: disable=no-member + self.cores.idle_cores -= run_frame.num_cores + self.cores.booked_cores += run_frame.num_cores + # pylint: enable=no-member + running_frame.frameAttendantThread.start() except: pass diff --git a/rqd/tests/rqcore_test.py b/rqd/tests/rqcore_test.py index 6ea29de38..000ac49b0 100644 --- a/rqd/tests/rqcore_test.py +++ b/rqd/tests/rqcore_test.py @@ -652,8 +652,8 @@ def test_recoverCache_expiredFile(self, mockExists, mockTime, mockGetmtime): self.assertEqual(len(self.rqcore._RqCore__cache), 0) - - def test_recoverCache_validBackup(self): + @mock.patch("rqd.rqcore.FrameAttendantThread", autospec=True) + def test_recoverCache_validBackup(self, attendant_patch): """Test recoverCache skips frames that fail to parse""" self.rqcore.backup_cache_path = 'cache.dat' @@ -662,14 +662,18 @@ def test_recoverCache_validBackup(self): job_id = "job_id", job_name = "job_name", frame_id = frameId, - frame_name = "frame_name" + frame_name = "frame_name", + num_cores = 4 ) running_frame = rqd.rqnetwork.RunningFrame(self.rqcore, frame) + self.rqcore.cores.idle_cores = 8 self.rqcore.storeFrame(frameId, running_frame) self.rqcore.backupCache() self.__cache = {} self.rqcore.recoverCache() self.assertIn('frame123', self.rqcore._RqCore__cache) + self.assertEqual(4, self.rqcore.cores.idle_cores) + self.assertEqual(4, self.rqcore.cores.booked_cores) def test_recoverCache_invalidFrame(self): """Test recoverCache loads frame data from valid backup file"""