Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoTavares committed Nov 19, 2024
1 parent 54c24a5 commit 54535b8
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions rqd/tests/rqcore_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ def test_runDocker(self, getTempDirMock, permsUser, timeMock, popenMock):
frameUid = 928
frameUsername = 'my-random-user'
returnCode = 0
softLimit = 2000000000
hardLimit = 5000000000
renderHost = rqd.compiled_proto.report_pb2.RenderHost(name='arbitrary-host-name')
logFile = os.path.join(logDir, '%s.%s.rqlog' % (jobName, frameName))

Expand Down Expand Up @@ -731,6 +733,7 @@ def test_runDocker(self, getTempDirMock, permsUser, timeMock, popenMock):

children = rqd.compiled_proto.report_pb2.ChildrenProcStats()

# Test Valid memory limit
runFrame = rqd.compiled_proto.rqd_pb2.RunFrame(
frame_id=frameId,
job_name=jobName,
Expand All @@ -741,8 +744,8 @@ def test_runDocker(self, getTempDirMock, permsUser, timeMock, popenMock):
children=children,
environment={"ENVVAR": "env_value"},
os="centos7",
soft_memory_limit=2000000000,
hard_memory_limit=5000000000)
soft_memory_limit=softLimit,
hard_memory_limit=hardLimit)
frameInfo = rqd.rqnetwork.RunningFrame(rqCore, runFrame)

# when
Expand All @@ -763,8 +766,8 @@ def test_runDocker(self, getTempDirMock, permsUser, timeMock, popenMock):
network="host",
stderr=True,
hostname=mock.ANY,
mem_reservation=2000000000,
mem_limit=5000000000,
mem_reservation=softLimit*1000,
mem_limit=hardLimit*1000,
entrypoint=cmd_file
)

Expand All @@ -775,6 +778,44 @@ def test_runDocker(self, getTempDirMock, permsUser, timeMock, popenMock):
frameInfo
)

### Test minimum memory limit
runFrame = rqd.compiled_proto.rqd_pb2.RunFrame(
frame_id=frameId,
job_name=jobName,
frame_name=frameName,
uid=frameUid,
user_name=frameUsername,
log_dir=logDir,
children=children,
environment={"ENVVAR": "env_value"},
os="centos7",
soft_memory_limit=1,
hard_memory_limit=2)
frameInfo = rqd.rqnetwork.RunningFrame(rqCore, runFrame)

# when
attendantThread = rqd.rqcore.FrameAttendantThread(rqCore, runFrame, frameInfo)
attendantThread.start()
attendantThread.join()

# then
cmd_file = os.path.join(tempDir, 'rqd-cmd-%s-%s' % (runFrame.frame_id, currentTime))
rqCore.docker.from_env.return_value.containers.run.assert_called_with(
image="centos7_image",
detach=True,
environment=mock.ANY,
working_dir=jobTempPath,
mounts=rqCore.docker_mounts,
privileged=True,
pid_mode="host",
network="host",
stderr=True,
hostname=mock.ANY,
mem_reservation="1GB",
mem_limit="2GB",
entrypoint=cmd_file
)


# TODO(bcipriano) Re-enable this test once Windows is supported. The main sticking point here
# is that the log directory is always overridden on Windows which makes mocking difficult.
Expand Down

0 comments on commit 54535b8

Please sign in to comment.