Skip to content

Commit 5dfc590

Browse files
authored
Merge pull request #1061 from bluetech/scheduling-proto
Add a Scheduling Protocol
2 parents 91812bf + bf2dccc commit 5dfc590

File tree

6 files changed

+72
-10
lines changed

6 files changed

+72
-10
lines changed

src/xdist/dsession.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from xdist.scheduler import LoadGroupScheduling
1616
from xdist.scheduler import LoadScheduling
1717
from xdist.scheduler import LoadScopeScheduling
18+
from xdist.scheduler import Scheduling
1819
from xdist.scheduler import WorkStealingScheduling
1920
from xdist.workermanage import NodeManager
2021

@@ -97,17 +98,21 @@ def pytest_collection(self):
9798
return True
9899

99100
@pytest.hookimpl(trylast=True)
100-
def pytest_xdist_make_scheduler(self, config, log):
101+
def pytest_xdist_make_scheduler(self, config, log) -> Scheduling | None:
101102
dist = config.getvalue("dist")
102-
schedulers = {
103-
"each": EachScheduling,
104-
"load": LoadScheduling,
105-
"loadscope": LoadScopeScheduling,
106-
"loadfile": LoadFileScheduling,
107-
"loadgroup": LoadGroupScheduling,
108-
"worksteal": WorkStealingScheduling,
109-
}
110-
return schedulers[dist](config, log)
103+
if dist == "each":
104+
return EachScheduling(config, log)
105+
if dist == "load":
106+
return LoadScheduling(config, log)
107+
if dist == "loadscope":
108+
return LoadScopeScheduling(config, log)
109+
if dist == "loadfile":
110+
return LoadFileScheduling(config, log)
111+
if dist == "loadgroup":
112+
return LoadGroupScheduling(config, log)
113+
if dist == "worksteal":
114+
return WorkStealingScheduling(config, log)
115+
return None
111116

112117
@pytest.hookimpl
113118
def pytest_runtestloop(self):

src/xdist/scheduler/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
from xdist.scheduler.loadfile import LoadFileScheduling as LoadFileScheduling
44
from xdist.scheduler.loadgroup import LoadGroupScheduling as LoadGroupScheduling
55
from xdist.scheduler.loadscope import LoadScopeScheduling as LoadScopeScheduling
6+
from xdist.scheduler.protocol import Scheduling as Scheduling
67
from xdist.scheduler.worksteal import WorkStealingScheduling as WorkStealingScheduling

src/xdist/scheduler/each.py

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ def mark_test_complete(self, node, item_index, duration=0):
103103
def mark_test_pending(self, item):
104104
raise NotImplementedError()
105105

106+
def remove_pending_tests_from_node(self, node, indices):
107+
raise NotImplementedError()
108+
106109
def remove_node(self, node):
107110
# KeyError if we didn't get an add_node() yet
108111
pending = self.node2pending.pop(node)

src/xdist/scheduler/load.py

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def mark_test_pending(self, item):
160160
for node in self.node2pending:
161161
self.check_schedule(node)
162162

163+
def remove_pending_tests_from_node(self, node, indices):
164+
raise NotImplementedError()
165+
163166
def check_schedule(self, node, duration=0):
164167
"""Maybe schedule new items on the node.
165168

src/xdist/scheduler/loadscope.py

+3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ def mark_test_complete(self, node, item_index, duration=0):
244244
def mark_test_pending(self, item):
245245
raise NotImplementedError()
246246

247+
def remove_pending_tests_from_node(self, node, indices):
248+
raise NotImplementedError()
249+
247250
def _assign_work_unit(self, node):
248251
"""Assign a work unit to a node."""
249252
assert self.workqueue

src/xdist/scheduler/protocol.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from __future__ import annotations
2+
3+
from typing import Protocol
4+
from typing import Sequence
5+
6+
from xdist.workermanage import WorkerController
7+
8+
9+
class Scheduling(Protocol):
10+
@property
11+
def nodes(self) -> list[WorkerController]: ...
12+
13+
@property
14+
def collection_is_completed(self) -> bool: ...
15+
16+
@property
17+
def tests_finished(self) -> bool: ...
18+
19+
@property
20+
def has_pending(self) -> bool: ...
21+
22+
def add_node(self, node: WorkerController) -> None: ...
23+
24+
def add_node_collection(
25+
self,
26+
node: WorkerController,
27+
collection: Sequence[str],
28+
) -> None: ...
29+
30+
def mark_test_complete(
31+
self,
32+
node: WorkerController,
33+
item_index: int,
34+
duration: float = 0,
35+
) -> None: ...
36+
37+
def mark_test_pending(self, item: str) -> None: ...
38+
39+
def remove_pending_tests_from_node(
40+
self,
41+
node: WorkerController,
42+
indices: Sequence[int],
43+
) -> None: ...
44+
45+
def remove_node(self, node: WorkerController) -> str | None: ...
46+
47+
def schedule(self) -> None: ...

0 commit comments

Comments
 (0)