Skip to content

Commit

Permalink
Fix unit tests and add core counting to recovery logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoTavares committed Dec 11, 2024
1 parent 7968673 commit bda928c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions rqd/rqd/rqcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions rqd/tests/rqcore_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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"""
Expand Down

0 comments on commit bda928c

Please sign in to comment.