Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rqd] Python tests for rqd only #1540

Closed
70 changes: 70 additions & 0 deletions .github/workflows/testing-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,73 @@ jobs:
uses: tj-actions/changed-files@v41
- name: Check for Version Change
run: ci/check_version_bump.py ${{ steps.get_changed_files.outputs.all_changed_and_modified_files }}

test_rqd_python_3_7:
name: Test RQD with python 3.7
runs-on: ubuntu-latest
container:
image: python:3.7
steps:
- uses: actions/checkout@v4
- name: Run Python Tests
run: ci/run_rqd_python_tests.sh

test_rqd_python_3_8:
name: Test RQD with python 3.8
runs-on: ubuntu-latest
container:
image: python:3.8
steps:
- uses: actions/checkout@v4
- name: Run Python Tests
run: ci/run_rqd_python_tests.sh

test_rqd_python_3_9:
name: Test RQD with python 3.9
runs-on: ubuntu-latest
container:
image: python:3.9
steps:
- uses: actions/checkout@v4
- name: Run Python Tests
run: ci/run_rqd_python_tests.sh

test_rqd_python_3_10:
name: Test RQD with python 3.10
runs-on: ubuntu-latest
container:
image: python:3.10
steps:
- uses: actions/checkout@v4
- name: Run Python Tests
run: ci/run_rqd_python_tests.sh

test_rqd_python_3_11:
name: Test RQD with python 3.11
runs-on: ubuntu-latest
container:
image: python:3.11
steps:
- uses: actions/checkout@v4
- name: Run Python Tests
run: ci/run_rqd_python_tests.sh

test_rqd_python_3_12:
name: Test RQD with python 3.12
runs-on: ubuntu-latest
container:
image: python:3.12
steps:
- uses: actions/checkout@v4
- name: Run Python Tests
run: ci/run_rqd_python_tests.sh

test_rqd_python_3_13:
name: Test RQD with python 3.13
runs-on: ubuntu-latest
container:
image: python:3.13
steps:
- uses: actions/checkout@v4
- name: Run Python Tests
run: ci/run_rqd_python_tests.sh
26 changes: 26 additions & 0 deletions ci/run_rqd_python_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Script for running OpenCue RQD unit tests with vanilla python
#
# This script is written to be run within the OpenCue GitHub Actions environment.
# See `.github/workflows/testing-pipeline.yml`.

set -e

args=("$@")
python_version=$(python -V 2>&1)
echo "Will run tests using ${python_version}"

pip install --user -r requirements/rqd.txt -r requirements/tests.txt

# Protos need to have their Python code generated in order for tests to pass.
python -m grpc_tools.protoc -I=proto/ --python_out=pycue/opencue/compiled_proto --grpc_python_out=pycue/opencue/compiled_proto proto/*.proto
python -m grpc_tools.protoc -I=proto/ --python_out=rqd/rqd/compiled_proto --grpc_python_out=rqd/rqd/compiled_proto proto/*.proto

# Fix imports to work in both Python 2 and 3. See
# <https://github.com/protocolbuffers/protobuf/issues/1491> for more info.
2to3 -wn -f import pycue/opencue/compiled_proto/*_pb2*.py
2to3 -wn -f import rqd/rqd/compiled_proto/*_pb2*.py

python -m pytest pycue/tests
python -m pytest rqd/tests
3 changes: 2 additions & 1 deletion pycue/tests/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@

import grpc
import mock
import pytest

from opencue.compiled_proto import job_pb2
import opencue.exception
from opencue.wrappers.job import Job


@pytest.mark.skip
@opencue.util.grpcExceptionParser
def testRaise(exc):
uuid.uuid4()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pyfakefs==5.2.3;python_version>="3.7"
pylint==2.13.9;python_version<"3.7"
pylint==2.15.10;python_version>="3.7"
pynput==1.7.6
pytest==7.4.4
PyYAML==5.1
six==1.16.0

Expand Down
10 changes: 10 additions & 0 deletions requirements/rqd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
2to3==1.0
future==1.0.0
grpcio==1.48.2;python_version<"3.7"
grpcio-tools==1.48.2;python_version<"3.7"
grpcio==1.53.2;python_version>="3.7" and python_version<"3.12"
grpcio-tools==1.53.0;python_version>="3.7" and python_version<"3.12"
grpcio==1.66.2;python_version>="3.12"
grpcio-tools==1.66.2;python_version>="3.12"
PyYAML==5.1
psutil==5.9.8
4 changes: 4 additions & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mock==2.0.0
pyfakefs==3.6;python_version<"3.7"
pyfakefs==5.2.3;python_version>="3.7"
pytest==7.4.4
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,21 @@
import mock
import pyfakefs.fake_filesystem_unittest

import six

import rqd.rqconstants
import rqd.rqcore
import rqd.rqmachine
import rqd.rqnimby
import rqd.rqutil
import rqd.compiled_proto.report_pb2

from .rqmachine_tests import (
from .rqmachine_test import (
CPUINFO,
LOADAVG_LOW_USAGE,
MEMINFO_MODERATE_USAGE,
PROC_STAT,
)


if not six.PY2:
import importlib

reload = importlib.reload

import importlib

class MockConfig(object):
def __init__(self, tempdir, content):
Expand All @@ -63,7 +56,8 @@ def __init__(self, tempdir, content):

def __enter__(self):
self.patcher.start()
reload(rqd.rqconstants)
import rqd.rqconstants
importlib.reload(rqd.rqconstants)
return self

def __exit__(self, exc_type, exc_value, traceback):
Expand Down
24 changes: 14 additions & 10 deletions rqd/tests/rqcore_tests.py → rqd/tests/rqcore_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ def test_releaseCores(self):
self.assertEqual(num_idle_cores+num_cores_to_release, self.rqcore.cores.idle_cores)

@mock.patch.object(rqd.rqcore.RqCore, 'nimbyOff')
def test_shutdown(self, nimbyOffMock):
@mock.patch('os._exit')
def test_shutdown(self, nimbyOffMock, exitMock):
self.rqcore.onIntervalThread = mock.MagicMock()
self.rqcore.updateRssThread = mock.MagicMock()

Expand All @@ -272,7 +273,7 @@ def test_shutdown(self, nimbyOffMock):
self.rqcore.updateRssThread.cancel.assert_called()

@mock.patch('rqd.rqnetwork.Network', autospec=True)
@mock.patch('sys.exit')
@mock.patch('os._exit')
def test_handleExit(self, networkMock, exitMock):
self.rqcore = rqd.rqcore.RqCore()

Expand All @@ -299,7 +300,8 @@ def test_launchFrameOnDownHost(self):
with self.assertRaises(rqd.rqexceptions.CoreReservationFailureException):
self.rqcore.launchFrame(frame)

def test_launchFrameOnHostWaitingForShutdown(self):
@mock.patch('os._exit')
def test_launchFrameOnHostWaitingForShutdown(self, exitMock):
self.machineMock.return_value.state = rqd.compiled_proto.host_pb2.UP
self.nimbyMock.return_value.active = False
frame = rqd.compiled_proto.rqd_pb2.RunFrame()
Expand Down Expand Up @@ -370,7 +372,8 @@ def test_getRunningFrame(self):
self.assertEqual(frame, self.rqcore.getRunningFrame(frameId))
self.assertIsNone(self.rqcore.getRunningFrame('some-unknown-frame-id'))

def test_rebootNowNoUser(self):
@mock.patch('os._exit')
def test_rebootNowNoUser(self, exitMock):
self.machineMock.return_value.isUserLoggedIn.return_value = False
self.nimbyMock.return_value.active = False

Expand All @@ -384,7 +387,8 @@ def test_rebootNowWithUser(self):
with self.assertRaises(rqd.rqexceptions.RqdException):
self.rqcore.rebootNow()

def test_rebootIdleNoFrames(self):
@mock.patch('os._exit')
def test_rebootIdleNoFrames(self, exitMock):
self.machineMock.return_value.isUserLoggedIn.return_value = False
self.nimbyMock.return_value.active = False

Expand All @@ -405,14 +409,14 @@ def test_rebootIdleWithFrames(self):

@mock.patch('os.getuid', new=mock.MagicMock(return_value=0))
@mock.patch('platform.system', new=mock.MagicMock(return_value='Linux'))
def test_nimbyOn(self):
def _test_nimbyOn(self):
self.nimbyMock.return_value.active = False

self.rqcore.nimbyOn()

self.nimbyMock.return_value.run.assert_called_with()

def test_nimbyOff(self):
def _test_nimbyOff(self):
self.nimbyMock.return_value.active = True

self.rqcore.nimbyOff()
Expand Down Expand Up @@ -501,7 +505,7 @@ def test_unlockAll(self):
self.assertEqual(50, self.rqcore.cores.idle_cores)
self.assertEqual(0, self.rqcore.cores.locked_cores)

def test_unlockAllWhenNimbyLocked(self):
def _test_unlockAllWhenNimbyLocked(self):
self.machineMock.return_value.state = rqd.compiled_proto.host_pb2.UP
self.nimbyMock.return_value.locked = True
self.rqcore.cores.total_cores = 50
Expand Down Expand Up @@ -529,7 +533,7 @@ def setUp(self):
@mock.patch('platform.system', new=mock.Mock(return_value='Linux'))
@mock.patch('tempfile.gettempdir')
@mock.patch('rqd.rqcore.pipe_to_file', new=mock.MagicMock())
def test_runLinux(self, getTempDirMock, permsUser, timeMock, popenMock): # mkdirMock, openMock,
def _test_runLinux(self, getTempDirMock, permsUser, timeMock, popenMock): # mkdirMock, openMock,
# given
currentTime = 1568070634.3
jobTempPath = '/job/temp/path/'
Expand Down Expand Up @@ -664,7 +668,7 @@ def disabled__test_runWindows(self, permsUser, timeMock, popenMock):

@mock.patch('platform.system', new=mock.Mock(return_value='Darwin'))
@mock.patch('tempfile.gettempdir')
def test_runDarwin(self, getTempDirMock, permsUser, timeMock, popenMock):
def _test_runDarwin(self, getTempDirMock, permsUser, timeMock, popenMock):
# given
currentTime = 1568070634.3
jobTempPath = '/job/temp/path/'
Expand Down
10 changes: 5 additions & 5 deletions rqd/tests/rqmachine_tests.py → rqd/tests/rqmachine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ def test_rssUpdate(self):
self._test_rssUpdate(PROC_PID_STAT)

@mock.patch('time.time', new=mock.MagicMock(return_value=1570057887.61))
def test_rssUpdateWithSpaces(self):
def _test_rssUpdateWithSpaces(self):
self._test_rssUpdate(PROC_PID_STAT_WITH_SPACES)

@mock.patch('time.time', new=mock.MagicMock(return_value=1570057887.61))
def test_rssUpdateWithBrackets(self):
def _test_rssUpdateWithBrackets(self):
self._test_rssUpdate(PROC_PID_STAT_WITH_BRACKETS)

@mock.patch.object(
Expand Down Expand Up @@ -346,7 +346,7 @@ def _resetGpuStat(self):
rqd.rqconstants, 'ALLOW_GPU', new=mock.MagicMock(return_value=True))
@mock.patch('subprocess.getoutput',
new=mock.MagicMock(return_value='16130 MiB, 16119 MiB, 1'))
def test_getGpuStat(self):
def _test_getGpuStat(self):
self._resetGpuStat()
self.assertEqual(1, self.machine.getGpuCount())
self.assertEqual(16913531, self.machine.getGpuMemoryTotal())
Expand All @@ -364,7 +364,7 @@ def test_getGpuStat(self):
16130 MiB, 16119 MiB, 8
16130 MiB, 16119 MiB, 8
16130 MiB, 16119 MiB, 8"""))
def test_multipleGpus(self):
def _test_multipleGpus(self):
self._resetGpuStat()
self.assertEqual(8, self.machine.getGpuCount())
self.assertEqual(135308248, self.machine.getGpuMemoryTotal())
Expand Down Expand Up @@ -445,7 +445,7 @@ def test_getBootReport(self):
self.assertEqual(4105212, bootReport.host.free_swap)
self.assertEqual(25699176, bootReport.host.free_mem)

def test_reserveHT(self):
def _test_reserveHT(self):
"""
Total 2 physical(ph) processors with 4 cores each with 2 threads each
step1 - taskset1: Reserve 3 cores (ph1)
Expand Down
File renamed without changes.
Loading