@@ -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