MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / test_task_priorities

Function test_task_priorities

tests/pyapi/test_job.py:195–218  ·  view source on GitHub ↗

Submits tasks with different randomly shuffled priorities and checks that tasks are executed in this order

(hq_env: HqEnv)

Source from the content-addressed store, hash-verified

193
194
195def test_task_priorities(hq_env: HqEnv):
196 """Submits tasks with different randomly shuffled priorities and
197 checks that tasks are executed in this order
198 """
199 (job, client) = prepare_job_client(hq_env)
200
201 priorities = list(range(-20, 20))
202 random.seed(123123)
203 random.shuffle(priorities)
204 for p in priorities:
205 if random.randint(0, 1) == 0:
206 job.program(bash("echo Hello"), priority=p)
207 else:
208 job.function(lambda: 0, priority=p)
209 job_id = client.submit(job)
210 client.wait_for_jobs([job_id])
211 data = hq_env.command(["--output-mode=json", "task", "list", "1"], as_json=True)["1"]
212
213 starts1 = [(props["id"], iso8601.parse_date(props["started_at"])) for props in data]
214 starts2 = starts1[:]
215
216 starts1.sort(key=lambda x: -priorities[x[0]])
217 starts2.sort(key=lambda x: x[1])
218 assert starts1 == starts2
219
220
221def test_resource_uniqueness_priorities(hq_env: HqEnv):

Callers

nothing calls this directly

Calls 8

prepare_job_clientFunction · 0.85
bashFunction · 0.85
programMethod · 0.80
functionMethod · 0.80
commandMethod · 0.80
sortMethod · 0.80
submitMethod · 0.45
wait_for_jobsMethod · 0.45

Tested by

no test coverage detected