Skip to content

Commit 3c0b88c

Browse files
committed
Test runs priority
1 parent 4edf247 commit 3c0b88c

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

src/dstack/_internal/server/testing/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ async def create_run(
262262
run_spec: Optional[RunSpec] = None,
263263
run_id: Optional[UUID] = None,
264264
deleted: bool = False,
265+
priority: int = 0,
265266
) -> RunModel:
266267
if run_spec is None:
267268
run_spec = get_run_spec(
@@ -282,6 +283,7 @@ async def create_run(
282283
run_spec=run_spec.json(),
283284
last_processed_at=submitted_at,
284285
jobs=[],
286+
priority=priority,
285287
)
286288
session.add(run)
287289
await session.commit()

src/tests/_internal/server/background/tasks/test_process_submitted_jobs.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,3 +634,63 @@ async def test_creates_new_instance_in_existing_fleet(self, test_db, session: As
634634
assert job.instance is not None
635635
assert job.instance.instance_num == 1
636636
assert job.instance.fleet_id == fleet.id
637+
638+
@pytest.mark.asyncio
639+
@pytest.mark.parametrize("test_db", ["sqlite", "postgres"], indirect=True)
640+
async def test_picks_high_priority_jobs_first(self, test_db, session: AsyncSession):
641+
project = await create_project(session)
642+
user = await create_user(session)
643+
repo = await create_repo(
644+
session=session,
645+
project_id=project.id,
646+
)
647+
instance = await create_instance(
648+
session=session,
649+
project=project,
650+
status=InstanceStatus.IDLE,
651+
)
652+
run1 = await create_run(
653+
session=session,
654+
project=project,
655+
repo=repo,
656+
user=user,
657+
priority=10,
658+
)
659+
job1 = await create_job(
660+
session=session,
661+
run=run1,
662+
instance_assigned=True,
663+
instance=instance,
664+
)
665+
run2 = await create_run(
666+
session=session,
667+
project=project,
668+
repo=repo,
669+
user=user,
670+
priority=0,
671+
)
672+
job2 = await create_job(
673+
session=session, run=run2, instance_assigned=True, instance=instance
674+
)
675+
run3 = await create_run(
676+
session=session,
677+
project=project,
678+
repo=repo,
679+
user=user,
680+
priority=100,
681+
)
682+
job3 = await create_job(
683+
session=session,
684+
run=run3,
685+
instance_assigned=True,
686+
instance=instance,
687+
)
688+
await process_submitted_jobs()
689+
await session.refresh(job3)
690+
assert job3.status == JobStatus.PROVISIONING
691+
await process_submitted_jobs()
692+
await session.refresh(job1)
693+
assert job1.status == JobStatus.PROVISIONING
694+
await process_submitted_jobs()
695+
await session.refresh(job2)
696+
assert job2.status == JobStatus.PROVISIONING

0 commit comments

Comments
 (0)