diff options
-rw-r--r-- | buildscripts/resmokelib/core/jasper_process.py | 6 | ||||
-rw-r--r-- | buildscripts/tests/resmokelib/core/test_jasper_process.py | 89 | ||||
-rw-r--r-- | etc/pip/components/resmoke.req | 4 |
3 files changed, 97 insertions, 2 deletions
diff --git a/buildscripts/resmokelib/core/jasper_process.py b/buildscripts/resmokelib/core/jasper_process.py index 64cf23edacc..fbef9da1921 100644 --- a/buildscripts/resmokelib/core/jasper_process.py +++ b/buildscripts/resmokelib/core/jasper_process.py @@ -16,6 +16,9 @@ from buildscripts.resmokelib.core import process as _process from buildscripts.resmokelib.logging.jasper_logger import get_logger_config from buildscripts.resmokelib.testing.fixtures import interface as fixture_interface +# The pids of processes spawned by jasper in resmoke +JASPER_PIDS = set() + class Process(_process.Process): """Class for spawning a process using mongodb/jasper.""" @@ -52,6 +55,7 @@ class Process(_process.Process): val = self._stub.Create(create_options) self.pid = val.pid + JASPER_PIDS.add(self.pid) self._id = self.pb.JasperProcessID(value=val.id) self._return_code = None @@ -72,6 +76,7 @@ class Process(_process.Process): signal_process = self.pb.SignalProcess(ProcessID=self._id, signal=signal) val = self._stub.Signal(signal_process) + JASPER_PIDS.discard(self.pid) if not val.success \ and "cannot signal a process that has terminated" not in val.text \ and "os: process already finished" not in val.text: @@ -91,4 +96,5 @@ class Process(_process.Process): if self._return_code is None: wait = self._stub.Wait(self._id) self._return_code = wait.exit_code + JASPER_PIDS.discard(self.pid) return self._return_code diff --git a/buildscripts/tests/resmokelib/core/test_jasper_process.py b/buildscripts/tests/resmokelib/core/test_jasper_process.py new file mode 100644 index 00000000000..0c6098c7a7c --- /dev/null +++ b/buildscripts/tests/resmokelib/core/test_jasper_process.py @@ -0,0 +1,89 @@ +"""Unit tests for buildscripts/resmokelib/core/jasper_process.py.""" +# pylint: disable=missing-docstring,protected-access +import logging +import unittest + +from mock import MagicMock + +from buildscripts.resmokelib import config +from buildscripts.resmokelib import run +from buildscripts.resmokelib.core import jasper_process as test_jasper_process + + +class TestJasperPids(unittest.TestCase): + resmoke_runner: run.TestRunner + + @classmethod + def setUpClass(cls) -> None: + resmoke_config = config + resmoke_config.BASE_PORT = 20000 + run.config = resmoke_config + test_jasper_process.config = resmoke_config + run.jasper_process = test_jasper_process + cls.resmoke_runner = run.TestRunner("jasper") + cls.resmoke_runner._resmoke_logger = MagicMock() + cls.resmoke_runner._setup_jasper() + cls.orig_jasper_pids = test_jasper_process.JASPER_PIDS.copy() + + @classmethod + def tearDownClass(cls) -> None: + cls.resmoke_runner._exit_jasper() + + def setUp(self) -> None: + test_jasper_process.JASPER_PIDS = self.orig_jasper_pids.copy() + + def test_pid_is_recorded(self) -> None: + test_pid = "1111" + test_proc = test_jasper_process.Process( + logging.Logger("jasper"), ["jasper"], job_num=1, test_id=1) + test_proc._stub.Create = MagicMock(return_value=MagicMock(pid=test_pid, id="1")) + test_proc.start() + self.assertEqual(test_pid, test_proc.pid) + self.assertEqual(len(test_jasper_process.JASPER_PIDS), 1) + self.assertTrue(test_pid in test_jasper_process.JASPER_PIDS) + + def test_pids_are_recorded(self) -> None: + test_pids = ["1111", "2222", "3333"] + for pid in test_pids: + test_proc = test_jasper_process.Process( + logging.Logger("jasper"), ["jasper"], job_num=1, test_id=1) + test_proc._stub.Create = MagicMock(return_value=MagicMock(pid=pid, id="1")) + test_proc.start() + self.assertEqual(len(test_pids), len(test_jasper_process.JASPER_PIDS)) + self.assertTrue(all(pid in test_jasper_process.JASPER_PIDS for pid in test_pids)) + + def test_pid_is_removed_by_stop(self) -> None: + pids = ["1111", "2222", "3333"] + procs = [] + for pid in pids: + proc = test_jasper_process.Process( + logging.Logger("jasper"), ["jasper"], job_num=1, test_id=1) + proc._stub.Create = MagicMock(return_value=MagicMock(pid=pid, id="1")) + proc.start() + procs.append(proc) + + orig_recorded_num_pids = len(test_jasper_process.JASPER_PIDS) + test_proc = procs[1] + self.assertTrue(test_proc.pid in test_jasper_process.JASPER_PIDS) + test_proc._stub.Signal = MagicMock(return_value=MagicMock(success=True)) + test_proc.stop() + self.assertFalse(test_proc.pid in test_jasper_process.JASPER_PIDS) + self.assertEqual(orig_recorded_num_pids - len(test_jasper_process.JASPER_PIDS), 1) + + def test_pid_is_removed_by_wait(self) -> None: + pids = ["1111", "2222", "3333"] + procs = [] + for pid in pids: + proc = test_jasper_process.Process( + logging.Logger("jasper"), ["jasper"], job_num=1, test_id=1) + proc._stub.Create = MagicMock(return_value=MagicMock(pid=pid, id="1")) + proc.start() + procs.append(proc) + + orig_recorded_num_pids = len(test_jasper_process.JASPER_PIDS) + test_proc = procs[1] + self.assertTrue(test_proc.pid in test_jasper_process.JASPER_PIDS) + test_proc._stub.Wait = MagicMock(return_value=MagicMock(exit_code=0)) + test_proc.wait() + self.assertFalse(test_proc.pid in test_jasper_process.JASPER_PIDS) + self.assertEqual(orig_recorded_num_pids - len(test_jasper_process.JASPER_PIDS), 1) diff --git a/etc/pip/components/resmoke.req b/etc/pip/components/resmoke.req index 6ef9df49e24..d775049d0f4 100644 --- a/etc/pip/components/resmoke.req +++ b/etc/pip/components/resmoke.req @@ -8,8 +8,8 @@ shrub.py == 1.1.0 ocspresponder == 0.5.0 flask == 1.1.1 ocspbuilder == 0.10.2 -grpcio == 1.37.0; platform_machine == "x86_64" or platform_machine == "aarch64" or platform_machine == "arm64" -grpcio-tools == 1.37.0; platform_machine == "x86_64" or platform_machine == "aarch64" or platform_machine == "arm64" +grpcio == 1.37.0; platform_machine == "x86_64" or platform_machine == "aarch64" or platform_machine == "arm64" or sys_platform == "win32" +grpcio-tools == 1.37.0; platform_machine == "x86_64" or platform_machine == "aarch64" or platform_machine == "arm64" or sys_platform == "win32" googleapis-common-protos == 1.53.0 blackduck == 1.0.1 PyGithub == 1.53 |