@@ -94,41 +94,50 @@ def test_create_scheduler(self) -> None:
9494 self .assertIsInstance (scheduler , AWSBatchScheduler )
9595
9696 def test_submit_dryrun_with_share_id (self ) -> None :
97- scheduler = create_scheduler ("test" )
9897 app = _test_app ()
9998 cfg = AWSBatchOpts ({"queue" : "testqueue" , "share_id" : "fooshare" })
100- info = scheduler . _submit_dryrun (app , cfg )
99+ info = create_scheduler ( "test" ). submit_dryrun (app , cfg )
101100
102101 req = info .request
103102 job_def = req .job_def
104103 self .assertEqual (req .share_id , "fooshare" )
105104 # must be set for jobs submitted to a queue with scheduling policy
106105 self .assertEqual (job_def ["schedulingPriority" ], 0 )
107106
108- def test_submit_dryrun_with_priority (self ) -> None :
109- scheduler = create_scheduler ("test" )
110- app = _test_app ()
111-
107+ def test_submit_dryrun_with_priority_but_not_share_id (self ) -> None :
112108 with self .assertRaisesRegex (ValueError , "config value.*priority.*share_id" ):
113109 cfg = AWSBatchOpts ({"queue" : "testqueue" , "priority" : 42 })
114- info = scheduler . _submit_dryrun ( app , cfg )
110+ create_scheduler ( "test" ). submit_dryrun ( _test_app () , cfg )
115111
116- cfg = AWSBatchOpts (
117- {"queue" : "testqueue" , "share_id" : "fooshare" , "priority" : 42 }
118- )
119- info = scheduler ._submit_dryrun (app , cfg )
112+ def test_submit_dryrun_with_priority (self ) -> None :
113+ cfg = AWSBatchOpts ({"queue" : "testqueue" , "share_id" : "foo" , "priority" : 42 })
114+ info = create_scheduler ("test" ).submit_dryrun (_test_app (), cfg )
120115
121116 req = info .request
122117 job_def = req .job_def
123- self .assertEqual (req .share_id , "fooshare " )
118+ self .assertEqual (req .share_id , "foo " )
124119 self .assertEqual (job_def ["schedulingPriority" ], 42 )
125120
121+ @patch (
122+ "torchx.schedulers.aws_batch_scheduler.getpass.getuser" , return_value = "testuser"
123+ )
124+ def test_submit_dryrun_tags (self , _ ) -> None :
125+ # intentionally not specifying user in cfg to test default
126+ cfg = AWSBatchOpts ({"queue" : "ignored_in_test" })
127+ info = create_scheduler ("test" ).submit_dryrun (_test_app (), cfg )
128+ self .assertEqual (
129+ {
130+ "torchx.pytorch.org/version" : torchx .__version__ ,
131+ "torchx.pytorch.org/app-name" : "test" ,
132+ "torchx.pytorch.org/user" : "testuser" ,
133+ },
134+ info .request .job_def ["tags" ],
135+ )
136+
126137 @mock_rand ()
127138 def test_submit_dryrun (self ) -> None :
128- scheduler = create_scheduler ("test" )
129- app = _test_app ()
130- cfg = AWSBatchOpts ({"queue" : "testqueue" })
131- info = scheduler ._submit_dryrun (app , cfg )
139+ cfg = AWSBatchOpts ({"queue" : "testqueue" , "user" : "testuser" })
140+ info = create_scheduler ("test" ).submit_dryrun (_test_app (), cfg )
132141
133142 req = info .request
134143 self .assertEqual (req .share_id , None )
@@ -248,6 +257,7 @@ def test_submit_dryrun(self) -> None:
248257 "tags" : {
249258 "torchx.pytorch.org/version" : torchx .__version__ ,
250259 "torchx.pytorch.org/app-name" : "test" ,
260+ "torchx.pytorch.org/user" : "testuser" ,
251261 },
252262 },
253263 )
@@ -440,13 +450,13 @@ def _mock_scheduler(self) -> AWSBatchScheduler:
440450 {
441451 "jobArn" : "arn:aws:batch:us-west-2:495572122715:job/6afc27d7-3559-43ca-89fd-1007b6bf2546" ,
442452 "jobId" : "6afc27d7-3559-43ca-89fd-1007b6bf2546" ,
443- "jobName" : "echo-v1r560pmwn5t3c " ,
453+ "jobName" : "app-name-42 " ,
444454 "createdAt" : 1643949940162 ,
445455 "status" : "SUCCEEDED" ,
446456 "stoppedAt" : 1643950324125 ,
447457 "container" : {"exitCode" : 0 },
448458 "nodeProperties" : {"numNodes" : 2 },
449- "jobDefinition" : "arn:aws:batch:us-west-2:495572122715:job-definition/echo-v1r560pmwn5t3c :1" ,
459+ "jobDefinition" : "arn:aws:batch:us-west-2:495572122715:job-definition/app-name-42 :1" ,
450460 }
451461 ]
452462 }
@@ -568,11 +578,7 @@ def _mock_scheduler(self) -> AWSBatchScheduler:
568578 def test_submit (self ) -> None :
569579 scheduler = self ._mock_scheduler ()
570580 app = _test_app ()
571- cfg = AWSBatchOpts (
572- {
573- "queue" : "testqueue" ,
574- }
575- )
581+ cfg = AWSBatchOpts ({"queue" : "testqueue" })
576582
577583 info = scheduler ._submit_dryrun (app , cfg )
578584 id = scheduler .schedule (info )
@@ -610,34 +616,35 @@ def test_describe(self) -> None:
610616 def test_list (self ) -> None :
611617 scheduler = self ._mock_scheduler ()
612618 expected_apps = [
613- ListAppResponse (
614- app_id = "torchx:echo-v1r560pmwn5t3c" , state = AppState .SUCCEEDED
615- )
619+ ListAppResponse (app_id = "torchx:app-name-42" , state = AppState .SUCCEEDED )
616620 ]
617621 apps = scheduler .list ()
618- self .assertEqual (apps , expected_apps )
622+ self .assertEqual (expected_apps , apps )
623+
624+ def test_list_no_jobs (self ) -> None :
625+ scheduler = AWSBatchScheduler ("test" , client = MagicMock ())
626+ scheduler ._client .get_paginator .side_effect = MockPaginator (
627+ describe_job_queues = [
628+ {
629+ "jobQueues" : [
630+ {"jobQueueName" : "torchx" , "state" : "ENABLED" },
631+ ],
632+ }
633+ ],
634+ list_jobs = [{"jobSummaryList" : []}],
635+ )
636+
637+ self .assertEqual ([], scheduler .list ())
619638
620639 def test_log_iter (self ) -> None :
621640 scheduler = self ._mock_scheduler ()
622641 logs = scheduler .log_iter ("testqueue:app-name-42" , "echo" , k = 1 , regex = "foo.*" )
623- self .assertEqual (
624- list (logs ),
625- [
626- "foo\n " ,
627- "foobar\n " ,
628- ],
629- )
642+ self .assertEqual (list (logs ), ["foo\n " , "foobar\n " ])
630643
631644 def test_log_iter_running_job (self ) -> None :
632645 scheduler = self ._mock_scheduler_running_job ()
633646 logs = scheduler .log_iter ("testqueue:app-name-42" , "echo" , k = 1 , regex = "foo.*" )
634- self .assertEqual (
635- [
636- "foo\n " ,
637- "foobar\n " ,
638- ],
639- list (logs ),
640- )
647+ self .assertEqual (["foo\n " , "foobar\n " ], list (logs ))
641648
642649 def test_local_session (self ) -> None :
643650 a : object = _local_session ()
0 commit comments