@@ -94,41 +94,50 @@ def test_create_scheduler(self) -> None:
94
94
self .assertIsInstance (scheduler , AWSBatchScheduler )
95
95
96
96
def test_submit_dryrun_with_share_id (self ) -> None :
97
- scheduler = create_scheduler ("test" )
98
97
app = _test_app ()
99
98
cfg = AWSBatchOpts ({"queue" : "testqueue" , "share_id" : "fooshare" })
100
- info = scheduler . _submit_dryrun (app , cfg )
99
+ info = create_scheduler ( "test" ). submit_dryrun (app , cfg )
101
100
102
101
req = info .request
103
102
job_def = req .job_def
104
103
self .assertEqual (req .share_id , "fooshare" )
105
104
# must be set for jobs submitted to a queue with scheduling policy
106
105
self .assertEqual (job_def ["schedulingPriority" ], 0 )
107
106
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 :
112
108
with self .assertRaisesRegex (ValueError , "config value.*priority.*share_id" ):
113
109
cfg = AWSBatchOpts ({"queue" : "testqueue" , "priority" : 42 })
114
- info = scheduler . _submit_dryrun ( app , cfg )
110
+ create_scheduler ( "test" ). submit_dryrun ( _test_app () , cfg )
115
111
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 )
120
115
121
116
req = info .request
122
117
job_def = req .job_def
123
- self .assertEqual (req .share_id , "fooshare " )
118
+ self .assertEqual (req .share_id , "foo " )
124
119
self .assertEqual (job_def ["schedulingPriority" ], 42 )
125
120
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
+
126
137
@mock_rand ()
127
138
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 )
132
141
133
142
req = info .request
134
143
self .assertEqual (req .share_id , None )
@@ -248,6 +257,7 @@ def test_submit_dryrun(self) -> None:
248
257
"tags" : {
249
258
"torchx.pytorch.org/version" : torchx .__version__ ,
250
259
"torchx.pytorch.org/app-name" : "test" ,
260
+ "torchx.pytorch.org/user" : "testuser" ,
251
261
},
252
262
},
253
263
)
@@ -440,13 +450,13 @@ def _mock_scheduler(self) -> AWSBatchScheduler:
440
450
{
441
451
"jobArn" : "arn:aws:batch:us-west-2:495572122715:job/6afc27d7-3559-43ca-89fd-1007b6bf2546" ,
442
452
"jobId" : "6afc27d7-3559-43ca-89fd-1007b6bf2546" ,
443
- "jobName" : "echo-v1r560pmwn5t3c " ,
453
+ "jobName" : "app-name-42 " ,
444
454
"createdAt" : 1643949940162 ,
445
455
"status" : "SUCCEEDED" ,
446
456
"stoppedAt" : 1643950324125 ,
447
457
"container" : {"exitCode" : 0 },
448
458
"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" ,
450
460
}
451
461
]
452
462
}
@@ -568,11 +578,7 @@ def _mock_scheduler(self) -> AWSBatchScheduler:
568
578
def test_submit (self ) -> None :
569
579
scheduler = self ._mock_scheduler ()
570
580
app = _test_app ()
571
- cfg = AWSBatchOpts (
572
- {
573
- "queue" : "testqueue" ,
574
- }
575
- )
581
+ cfg = AWSBatchOpts ({"queue" : "testqueue" })
576
582
577
583
info = scheduler ._submit_dryrun (app , cfg )
578
584
id = scheduler .schedule (info )
@@ -610,34 +616,35 @@ def test_describe(self) -> None:
610
616
def test_list (self ) -> None :
611
617
scheduler = self ._mock_scheduler ()
612
618
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 )
616
620
]
617
621
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 ())
619
638
620
639
def test_log_iter (self ) -> None :
621
640
scheduler = self ._mock_scheduler ()
622
641
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 " ])
630
643
631
644
def test_log_iter_running_job (self ) -> None :
632
645
scheduler = self ._mock_scheduler_running_job ()
633
646
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 ))
641
648
642
649
def test_local_session (self ) -> None :
643
650
a : object = _local_session ()
0 commit comments