47
47
import enum
48
48
from math import ceil
49
49
import random
50
- from typing import cast
50
+ from typing import cast , List , Tuple
51
51
from typing import TYPE_CHECKING
52
52
53
53
import pytest
@@ -142,7 +142,7 @@ def __init__(self, config: pytest.Config, log: xdist.remote.Producer):
142
142
# is performed once the number of registered node collections reaches
143
143
# `_expected_num_workers`. It is initialized to None and then updated
144
144
# after validation succeeds.
145
- self ._official_test_collection : tuple [str , ...] | None = None
145
+ self ._official_test_collection : Tuple [str , ...] | None = None
146
146
# Remote worker node having `_official_test_collection` as its test
147
147
# collection (for reporting failed collection validations)
148
148
self ._official_test_collection_node : WorkerController | None = None
@@ -182,7 +182,7 @@ def __init__(self, config: pytest.Config, log: xdist.remote.Producer):
182
182
)
183
183
184
184
@property
185
- def nodes (self ) -> list [WorkerController ]:
185
+ def nodes (self ) -> List [WorkerController ]:
186
186
"""A new list of all active `WorkerController` nodes.
187
187
188
188
Called by xdist `DSession`.
@@ -371,7 +371,7 @@ def add_node_collection(
371
371
WorkerController , self ._official_test_collection_node
372
372
),
373
373
reference_collection = cast (
374
- tuple [str , ...], self ._official_test_collection
374
+ Tuple [str , ...], self ._official_test_collection
375
375
),
376
376
node = node ,
377
377
collection = collection ,
@@ -404,9 +404,9 @@ def add_node_collection(
404
404
for pending_worker in workers_with_collection [1 :]:
405
405
if not self ._do_two_nodes_have_same_collection (
406
406
reference_node = reference_worker .node ,
407
- reference_collection = cast (tuple [str , ...], reference_worker .collection ),
407
+ reference_collection = cast (Tuple [str , ...], reference_worker .collection ),
408
408
node = pending_worker .node ,
409
- collection = cast (tuple [str , ...], pending_worker .collection ),
409
+ collection = cast (Tuple [str , ...], pending_worker .collection ),
410
410
):
411
411
same_collection = False
412
412
@@ -433,7 +433,7 @@ def add_node_collection(
433
433
all_tests = [
434
434
_TestProxy (test_id = test_id , test_index = test_index )
435
435
for test_index , test_id in enumerate (
436
- cast (tuple [str , ...], self ._official_test_collection )
436
+ cast (Tuple [str , ...], self ._official_test_collection )
437
437
)
438
438
]
439
439
shuffled_test_collection = random .sample (all_tests , k = len (all_tests ))
@@ -460,7 +460,7 @@ def mark_test_complete(
460
460
if self ._log .enabled :
461
461
self ._log (
462
462
f"Marking test complete: "
463
- f"test_id={ cast (tuple [str , ...], self ._official_test_collection )[item_index ]} ; "
463
+ f"test_id={ cast (Tuple [str , ...], self ._official_test_collection )[item_index ]} ; "
464
464
f"{ item_index = } ; { worker } "
465
465
)
466
466
@@ -534,7 +534,7 @@ def _reschedule_workers(self) -> None:
534
534
"""Distribute work to workers if needed at this time."""
535
535
assert self ._state is not None
536
536
537
- traversed_states : list [IsoScopeScheduling ._State ] = []
537
+ traversed_states : List [IsoScopeScheduling ._State ] = []
538
538
previous_state = None
539
539
while self ._state != previous_state :
540
540
# NOTE: This loop will terminate because completion of tests and
@@ -762,7 +762,7 @@ def _handle_state_fence(self) -> None:
762
762
self ._log (f"Transitioned from { previous_state !s} to " f"{ self ._state !s} " )
763
763
764
764
def _distribute_workset (
765
- self , workset : _ScopeWorkset , workers : list [_WorkerProxy ]
765
+ self , workset : _ScopeWorkset , workers : List [_WorkerProxy ]
766
766
) -> None :
767
767
"""Distribute the tests in the given workset to the given workers.
768
768
@@ -977,7 +977,7 @@ def _get_max_workers_for_num_tests(num_tests: int) -> int:
977
977
978
978
def _get_workers_available_for_distribution (
979
979
self , scope_id : str
980
- ) -> list [_WorkerProxy ]:
980
+ ) -> List [_WorkerProxy ]:
981
981
"""Return workers available for distribution of the given Scope.
982
982
983
983
Available workers are non-shutting-down workers that either
@@ -1001,7 +1001,7 @@ def _get_workers_available_for_distribution(
1001
1001
)
1002
1002
]
1003
1003
1004
- def _get_workers_ready_for_fencing (self , scope_id : str ) -> list [_WorkerProxy ]:
1004
+ def _get_workers_ready_for_fencing (self , scope_id : str ) -> List [_WorkerProxy ]:
1005
1005
"""Return workers that are ready to be Fenced for the given test Scope.
1006
1006
1007
1007
A worker that needs to be Fenced satisfies all the following conditions:
@@ -1026,9 +1026,9 @@ def _get_workers_ready_for_fencing(self, scope_id: str) -> list[_WorkerProxy]:
1026
1026
def _do_two_nodes_have_same_collection (
1027
1027
self ,
1028
1028
reference_node : WorkerController ,
1029
- reference_collection : tuple [str , ...],
1029
+ reference_collection : Tuple [str , ...],
1030
1030
node : WorkerController ,
1031
- collection : tuple [str , ...],
1031
+ collection : Tuple [str , ...],
1032
1032
) -> bool :
1033
1033
"""
1034
1034
If collections differ, this method returns False while logging
@@ -1079,7 +1079,7 @@ def __init__(self, node: WorkerController):
1079
1079
1080
1080
# An ordered collection of test IDs collected by the remote worker.
1081
1081
# Initially None, until assigned by the Scheduler
1082
- self ._collection : tuple [str , ...] | None = None
1082
+ self ._collection : Tuple [str , ...] | None = None
1083
1083
1084
1084
self ._pending_test_by_index : OrderedDict [int , _TestProxy ] = OrderedDict ()
1085
1085
@@ -1092,15 +1092,15 @@ def node(self) -> WorkerController:
1092
1092
return self ._node
1093
1093
1094
1094
@property
1095
- def collection (self ) -> tuple [str , ...] | None :
1095
+ def collection (self ) -> Tuple [str , ...] | None :
1096
1096
"""
1097
1097
:return: An ordered collection of test IDs collected by the remote
1098
1098
worker; `None` if the collection is not available yet.
1099
1099
"""
1100
1100
return self ._collection
1101
1101
1102
1102
@collection .setter
1103
- def collection (self , collection : tuple [str , ...]) -> None :
1103
+ def collection (self , collection : Tuple [str , ...]) -> None :
1104
1104
"""
1105
1105
:param collection: An ordered collection of test IDs collected by the
1106
1106
remote worker. Must not be `None`. Also, MUST NOT be set already.
@@ -1209,7 +1209,7 @@ def handle_test_completion(self, test_index: int) -> None:
1209
1209
# Remove the test from the worker's pending queue
1210
1210
self ._pending_test_by_index .pop (test_index )
1211
1211
1212
- def release_pending_tests (self ) -> list [_TestProxy ]:
1212
+ def release_pending_tests (self ) -> List [_TestProxy ]:
1213
1213
"""Reset the worker's pending tests, returning those pending tests.
1214
1214
1215
1215
:return: A (possibly empty) list of pending tests.
@@ -1314,7 +1314,7 @@ def enqueue_test(self, test: _TestProxy) -> None:
1314
1314
# Update high watermark
1315
1315
self ._high_water = max (self ._high_water , len (self ._test_by_index ))
1316
1316
1317
- def dequeue_tests (self , num_tests : int ) -> list [_TestProxy ]:
1317
+ def dequeue_tests (self , num_tests : int ) -> List [_TestProxy ]:
1318
1318
"""
1319
1319
Remove and return the given number of tests from the head of the
1320
1320
collection.
0 commit comments