Skip to content

Commit

Permalink
add queue size to test
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldg committed Mar 7, 2024
1 parent ad7c61e commit 56f4059
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
19 changes: 17 additions & 2 deletions tests/fixtures/scenario-locations-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tools:
import pathlib
from ruamel.yaml import YAML
from tpv.commands.test import mock_galaxy
from tpv.core.helpers import get_dataset_attributes
from tpv.core.helpers import get_dataset_attributes, concurrent_job_count_for_tool
# NOTE: currently object store info is stored in a yaml
objectstore_loc_path = "tests/fixtures/object_store_locations.yml"
Expand All @@ -35,7 +35,22 @@ tools:
# Define the URL of your FastAPI application
api_url = "http://localhost:8000/process_destinations"
candidate_destinations_list = [dest.to_dict() for dest in candidate_destinations]
print("APP:",dir(app.Job))
# test = app.model.context.query(model.Job).filter(model.Job.state == "queued", model.Job.destination_id == dest.dest_name).count()
# print(test)
candidate_destinations_list = []
for dest in candidate_destinations:
dest_dict = dest.to_dict()
dest_dict["queued_job_count"] = app.model.context.query(model.Job).filter(model.Job.state == "queued", model.Job.destination_id == dest.dest_name).count()
candidate_destinations_list.append(dest_dict)
print(candidate_destinations[0])
# candidate_destinations_list = [{"id": dest.id, "context": dest.context} for dest in candidate_destinations]
print(candidate_destinations_list)
input_data = {
"destinations": candidate_destinations_list,
Expand Down
36 changes: 35 additions & 1 deletion tests/test_scenarios_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,47 @@ def test_scenario_esg_group_user_api(self):
Each endpoint will have a user that does this.
"""

def create_job(app, destination):
sa_session = app.model.context

u = app.model.User(email="highmemuser@unimelb.edu.au", password="password")
j = app.model.Job()
j.user = u
j.tool_id = "trinity"
j.state = "running"
j.destination_id = destination

sa_session.add(j)
sa_session.flush()

def create_job_state_history(app, destination):
sa_session = app.model.context

u = app.model.User(email="highmemuser@unimelb.edu.au", password="password")
j = app.model.Job()
j.user = u
j.tool_id = "trinity"
j.state = state
j.destination_id = destination

sa_session.add(j)
sa_session.flush()

app = mock_galaxy.App(
job_conf=os.path.join(os.path.dirname(__file__), 'fixtures/job_conf_scenario_locations.yml'),
create_model=True)
create_job(app, "highmem_pulsar_1")
create_job(app, "highmem_pulsar_2")
create_job(app, "highmem_pulsar_1")
create_job(app, "highmem_pulsar_2")

tool = mock_galaxy.Tool('trinity')
user = mock_galaxy.User('pulsar-hm2-user', 'pulsar-hm2-user@unimelb.edu.au', roles=["ga_admins"])
datasets = [mock_galaxy.DatasetAssociation("input", mock_galaxy.Dataset("input.fastq",
file_size=1000*1024**3,
object_store_id="object_store_australia"))]
rules_file = os.path.join(os.path.dirname(__file__), 'fixtures/scenario-locations-api.yml')
destination = self._map_to_destination(tool, user, datasets=datasets, tpv_config_path=rules_file,
job_conf='fixtures/job_conf_scenario_locations.yml')
job_conf='fixtures/job_conf_scenario_locations.yml', app=app)
self.assertEqual(destination.id, "pulsar_australia")

0 comments on commit 56f4059

Please sign in to comment.