Submits tasks with different randomly shuffled priorities and checks that tasks are executed in this order
(hq_env: HqEnv)
| 193 | |
| 194 | |
| 195 | def 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 | |
| 221 | def test_resource_uniqueness_priorities(hq_env: HqEnv): |
nothing calls this directly
no test coverage detected