diff --git a/src/orca/services/synapse/ops.py b/src/orca/services/synapse/ops.py index dce1d9a..d8886d9 100644 --- a/src/orca/services/synapse/ops.py +++ b/src/orca/services/synapse/ops.py @@ -42,3 +42,18 @@ def fs(self) -> SynapseFS: raise ConfigError(message) return SynapseFS(auth_token=auth_token) + + def monitor_evaluation_queue(self, evaluation_id: str) -> bool: + """Monitor an evaluation queue in Synapse. + + Args: + evaluation_id: The Synapse ID of the queue to monitor. + + Returns: + True if there are "RECEIVED" submissions, False otherwise. + """ + received_submissions = self.client.getSubmissionBundles( + evaluation_id, status="RECEIVED" + ) + submissions_num = sum(1 for submission in received_submissions) + return submissions_num > 0 diff --git a/tests/services/synapse/conftest.py b/tests/services/synapse/conftest.py index c4a04c7..8e96e18 100644 --- a/tests/services/synapse/conftest.py +++ b/tests/services/synapse/conftest.py @@ -1,6 +1,30 @@ import pytest +from orca.services.synapse import SynapseClientFactory, SynapseConfig, SynapseOps + @pytest.fixture def syn_project_id(): yield "syn51469029" + + +@pytest.fixture +def config(patch_os_environ): + yield SynapseConfig("foo") + + +@pytest.fixture +def client(config): + factory = SynapseClientFactory(config=config) + yield factory.create_client() + + +@pytest.fixture +def mocked_ops(config, client, mocker): + mocker.patch.object(SynapseOps, "client", return_value=client) + yield SynapseOps(config) + + +@pytest.fixture +def ops(config): + yield SynapseOps(config) diff --git a/tests/services/synapse/test_ops.py b/tests/services/synapse/test_ops.py index 1067707..f446f59 100644 --- a/tests/services/synapse/test_ops.py +++ b/tests/services/synapse/test_ops.py @@ -10,3 +10,27 @@ def test_for_an_error_when_accessing_fs_without_credentials( ops = SynapseOps() with pytest.raises(ConfigError): ops.fs.listdir(syn_project_id) + + +def test_monitor_evaluation_queue_returns_false_when_there_are_no_new_submissions( + mocker, mocked_ops +): + mock = mocker.patch.object( + mocked_ops.client, "getSubmissionBundles", return_value=[] + ) + result = mocked_ops.monitor_evaluation_queue("foo") + mock.assert_called_once_with("foo", status="RECEIVED") + assert result is False + + +def test_monitor_evaluation_queue_returns_true_when_there_are_new_submissions( + mocker, mocked_ops +): + mock = mocker.patch.object( + mocked_ops.client, + "getSubmissionBundles", + return_value=["submission_1", "submission_2"], + ) + result = mocked_ops.monitor_evaluation_queue("foo") + mock.assert_called_once_with("foo", status="RECEIVED") + assert result