Skip to content

Commit

Permalink
Convert + improve test_job/task_metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Jun 10, 2024
1 parent 65530c9 commit 1d7d655
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 342 deletions.
321 changes: 0 additions & 321 deletions test/unit/data/db/conftest.py

This file was deleted.

14 changes: 14 additions & 0 deletions test/unit/data/model/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,20 @@ def f(**kwd):
return f


@pytest.fixture
def make_task(session, make_job):
def f(**kwd):
kwd["job"] = kwd.get("job") or make_job()
# Assumption: if the following args are needed, a test should supply them
kwd["working_directory"] = kwd.get("working_directory") or random_str()
kwd["prepare_files_cmd"] = kwd.get("prepare_files_cmd") or random_str()
model = m.Task(**kwd)
write_to_db(session, model)
return model

return f


@pytest.fixture
def make_user(session):
def f(**kwd):
Expand Down
31 changes: 31 additions & 0 deletions test/unit/data/model/db/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,34 @@ def test_metadata_spec(make_hda):
assert d.metadata.chromCol == 1
assert d.metadata.anyAttribute is None
assert "items" not in d.metadata


def test_job_metrics(make_job):
job = make_job()
job.add_metric("gx", "galaxy_slots", 5)
job.add_metric("system", "system_name", "localhost")

assert len(job.text_metrics) == 1
assert job.text_metrics[0].plugin == "system"
assert job.text_metrics[0].metric_name == "system_name"
assert job.text_metrics[0].metric_value == "localhost"
assert len(job.numeric_metrics) == 1
assert job.numeric_metrics[0].plugin == "gx"
assert job.numeric_metrics[0].metric_name == "galaxy_slots"
assert job.numeric_metrics[0].metric_value == 5


def test_task_metrics(make_task):
task = make_task()
task.add_metric("foo", "some-name", "some-value")
big_value = ":".join(f"{i}" for i in range(2000))
task.add_metric("env", "BIG_PATH", big_value)

assert len(task.text_metrics) == 2
assert task.text_metrics[0].plugin == "foo"
assert task.text_metrics[0].metric_name == "some-name"
assert task.text_metrics[0].metric_value == "some-value"
assert task.text_metrics[1].plugin == "env"
assert task.text_metrics[1].metric_name == "BIG_PATH"
# Ensure big values truncated
assert len(task.text_metrics[1].metric_value) <= 1023
Loading

0 comments on commit 1d7d655

Please sign in to comment.