Skip to content

Commit 1e7878e

Browse files
changed tests to check for specific usage values
also changed the values to be more recognizable
1 parent 8bb37d1 commit 1e7878e

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

openeo/rest/_testing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ def _handle_get_job(self, request, context):
231231
"status": self.batch_jobs[job_id]["status"],
232232
}
233233
if self.batch_jobs[job_id]["status"] == "finished": # HACK some realistic values for a small job
234-
result["costs"] = 4
234+
result["costs"] = 123
235235
result["usage"] = {
236-
"cpu": {"unit": "cpu-seconds", "value": 30.0},
237-
"duration": {"unit": "seconds", "value": 55},
238-
"memory": {"unit": "mb-seconds", "value": 150000.0},
236+
"cpu": {"unit": "cpu-seconds", "value": 1234.5},
237+
"memory": {"unit": "mb-seconds", "value": 34567.89},
238+
"duration": {"unit": "seconds", "value": 2345},
239239
}
240240
return result
241241

tests/extra/test_job_management.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# httpretty avoids this specific problem because it mocks at the socket level,
1919
# But I would rather not have two dependencies with almost the same goal.
2020
import httpretty
21+
import numpy as np
2122
import pandas
2223
import pandas as pd
2324
import pytest
@@ -166,16 +167,17 @@ def test_basic(self, tmp_path, job_manager, job_manager_root_dir, sleep_mock):
166167
}
167168
)
168169

169-
assert [(r.id, r.status, r.backend_name) for r in pd.read_csv(job_db_path).itertuples()] == [
170-
("job-2018", "finished", "foo"),
171-
("job-2019", "finished", "foo"),
172-
("job-2020", "finished", "bar"),
173-
("job-2021", "finished", "bar"),
174-
("job-2022", "finished", "foo"),
170+
assert [
171+
(r.id, r.status, r.backend_name, r.cpu, r.memory, r.duration, r.costs)
172+
for r in pd.read_csv(job_db_path).itertuples()
173+
] == [
174+
("job-2018", "finished", "foo", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
175+
("job-2019", "finished", "foo", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
176+
("job-2020", "finished", "bar", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
177+
("job-2021", "finished", "bar", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
178+
("job-2022", "finished", "foo", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
175179
]
176180

177-
assert not pd.read_csv(job_db_path)[["cpu", "memory", "duration", "costs"]].isnull().any().any()
178-
179181
# Check downloaded results and metadata.
180182
assert set(p.relative_to(job_manager_root_dir) for p in job_manager_root_dir.glob("**/*.*")) == {
181183
Path(f"job_{job_id}") / filename
@@ -206,7 +208,10 @@ def test_db_class(self, tmp_path, job_manager, job_manager_root_dir, sleep_mock,
206208
assert len(result) == 5
207209
assert set(result.status) == {"finished"}
208210
assert set(result.backend_name) == {"foo", "bar"}
209-
assert not result[["cpu", "memory", "duration", "costs"]].isnull().any().any()
211+
assert set(result.cpu) == {"1234.5 cpu-seconds"}
212+
assert set(result.memory) == {"34567.89 mb-seconds"}
213+
assert set(result.duration) == {"2345 seconds"}
214+
assert set(result.costs) == {123}
210215

211216
@pytest.mark.parametrize(
212217
["filename", "expected_db_class"],
@@ -257,16 +262,17 @@ def test_basic_threading(self, tmp_path, job_manager, job_manager_root_dir, slee
257262
# TODO #645 how to collect stats with the threaded run_job?
258263
assert sleep_mock.call_count > 10
259264

260-
assert [(r.id, r.status, r.backend_name) for r in pd.read_csv(job_db_path).itertuples()] == [
261-
("job-2018", "finished", "foo"),
262-
("job-2019", "finished", "foo"),
263-
("job-2020", "finished", "bar"),
264-
("job-2021", "finished", "bar"),
265-
("job-2022", "finished", "foo"),
265+
assert [
266+
(r.id, r.status, r.backend_name, r.cpu, r.memory, r.duration, r.costs)
267+
for r in pd.read_csv(job_db_path).itertuples()
268+
] == [
269+
("job-2018", "finished", "foo", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
270+
("job-2019", "finished", "foo", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
271+
("job-2020", "finished", "bar", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
272+
("job-2021", "finished", "bar", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
273+
("job-2022", "finished", "foo", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
266274
]
267275

268-
assert not pd.read_csv(job_db_path)[["cpu", "memory", "duration", "costs"]].isnull().any().any()
269-
270276
# Check downloaded results and metadata.
271277
assert set(p.relative_to(job_manager_root_dir) for p in job_manager_root_dir.glob("**/*.*")) == {
272278
Path(f"job_{job_id}") / filename
@@ -339,15 +345,16 @@ def start_worker_thread():
339345
)
340346

341347
# Also check that we got sensible end results in the job db.
342-
result = pd.read_csv(job_db_path)
343-
assert [(r.id, r.status, r.backend_name) for r in result.itertuples()] == [
344-
("job-2018", "finished", "foo"),
345-
("job-2019", "finished", "foo"),
346-
("job-2020", "finished", "bar"),
347-
("job-2021", "finished", "bar"),
348-
("job-2022", "error", "foo"),
348+
results = pd.read_csv(job_db_path).replace({np.nan: None}) # np.nan's are replaced by None for easy comparison
349+
assert [
350+
(r.id, r.status, r.backend_name, r.cpu, r.memory, r.duration, r.costs) for r in results.itertuples()
351+
] == [
352+
("job-2018", "finished", "foo", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
353+
("job-2019", "finished", "foo", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
354+
("job-2020", "finished", "bar", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
355+
("job-2021", "finished", "bar", "1234.5 cpu-seconds", "34567.89 mb-seconds", "2345 seconds", 123),
356+
("job-2022", "error", "foo", None, None, None, None),
349357
]
350-
assert not result[result["status"] == "finished"][["cpu", "memory", "duration", "costs"]].isnull().any().any()
351358

352359
# Check downloaded results and metadata.
353360
assert set(p.relative_to(job_manager_root_dir) for p in job_manager_root_dir.glob("**/*.*")) == {

0 commit comments

Comments
 (0)