Clean up scheduller interfaces
This commit is contained in:
@@ -54,13 +54,13 @@ class TestEachScheduling:
|
||||
node2 = MockNode()
|
||||
config = testdir.parseconfig("--tx=2*popen")
|
||||
sched = EachScheduling(config)
|
||||
sched.addnode(node1)
|
||||
sched.addnode(node2)
|
||||
sched.add_node(node1)
|
||||
sched.add_node(node2)
|
||||
collection = ["a.py::test_1", ]
|
||||
assert not sched.collection_is_completed
|
||||
sched.addnode_collection(node1, collection)
|
||||
sched.add_node_collection(node1, collection)
|
||||
assert not sched.collection_is_completed
|
||||
sched.addnode_collection(node2, collection)
|
||||
sched.add_node_collection(node2, collection)
|
||||
assert sched.collection_is_completed
|
||||
assert sched.node2collection[node1] == collection
|
||||
assert sched.node2collection[node2] == collection
|
||||
@@ -77,10 +77,10 @@ class TestEachScheduling:
|
||||
node1 = MockNode()
|
||||
config = testdir.parseconfig("--tx=popen")
|
||||
sched = EachScheduling(config)
|
||||
sched.addnode(node1)
|
||||
sched.add_node(node1)
|
||||
collection = ["a.py::test_1", ]
|
||||
assert not sched.collection_is_completed
|
||||
sched.addnode_collection(node1, collection)
|
||||
sched.add_node_collection(node1, collection)
|
||||
assert sched.collection_is_completed
|
||||
assert sched.node2collection[node1] == collection
|
||||
sched.schedule()
|
||||
@@ -88,21 +88,21 @@ class TestEachScheduling:
|
||||
crashitem = sched.remove_node(node1)
|
||||
assert crashitem
|
||||
assert sched.tests_finished()
|
||||
assert not sched.hasnodes()
|
||||
assert not sched.has_nodes()
|
||||
|
||||
|
||||
class TestLoadScheduling:
|
||||
def test_schedule_load_simple(self, testdir):
|
||||
config = testdir.parseconfig("--tx=2*popen")
|
||||
sched = LoadScheduling(config)
|
||||
sched.addnode(MockNode())
|
||||
sched.addnode(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
node1, node2 = sched.nodes
|
||||
collection = ["a.py::test_1", "a.py::test_2"]
|
||||
assert not sched.collection_is_completed
|
||||
sched.addnode_collection(node1, collection)
|
||||
sched.add_node_collection(node1, collection)
|
||||
assert not sched.collection_is_completed
|
||||
sched.addnode_collection(node2, collection)
|
||||
sched.add_node_collection(node2, collection)
|
||||
assert sched.collection_is_completed
|
||||
assert sched.node2collection[node1] == collection
|
||||
assert sched.node2collection[node2] == collection
|
||||
@@ -119,12 +119,12 @@ class TestLoadScheduling:
|
||||
def test_schedule_batch_size(self, testdir):
|
||||
config = testdir.parseconfig("--tx=2*popen")
|
||||
sched = LoadScheduling(config)
|
||||
sched.addnode(MockNode())
|
||||
sched.addnode(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
node1, node2 = sched.nodes
|
||||
col = ["xyz"] * (6)
|
||||
sched.addnode_collection(node1, col)
|
||||
sched.addnode_collection(node2, col)
|
||||
sched.add_node_collection(node1, col)
|
||||
sched.add_node_collection(node2, col)
|
||||
sched.schedule()
|
||||
# assert not sched.tests_finished()
|
||||
sent1 = node1.sent
|
||||
@@ -146,13 +146,13 @@ class TestLoadScheduling:
|
||||
def test_schedule_fewer_tests_than_nodes(self, testdir):
|
||||
config = testdir.parseconfig("--tx=2*popen")
|
||||
sched = LoadScheduling(config)
|
||||
sched.addnode(MockNode())
|
||||
sched.addnode(MockNode())
|
||||
sched.addnode(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
node1, node2, node3 = sched.nodes
|
||||
col = ["xyz"] * 2
|
||||
sched.addnode_collection(node1, col)
|
||||
sched.addnode_collection(node2, col)
|
||||
sched.add_node_collection(node1, col)
|
||||
sched.add_node_collection(node2, col)
|
||||
sched.schedule()
|
||||
# assert not sched.tests_finished()
|
||||
sent1 = node1.sent
|
||||
@@ -166,13 +166,13 @@ class TestLoadScheduling:
|
||||
def test_schedule_fewer_than_two_tests_per_node(self, testdir):
|
||||
config = testdir.parseconfig("--tx=2*popen")
|
||||
sched = LoadScheduling(config)
|
||||
sched.addnode(MockNode())
|
||||
sched.addnode(MockNode())
|
||||
sched.addnode(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
sched.add_node(MockNode())
|
||||
node1, node2, node3 = sched.nodes
|
||||
col = ["xyz"] * 5
|
||||
sched.addnode_collection(node1, col)
|
||||
sched.addnode_collection(node2, col)
|
||||
sched.add_node_collection(node1, col)
|
||||
sched.add_node_collection(node2, col)
|
||||
sched.schedule()
|
||||
# assert not sched.tests_finished()
|
||||
sent1 = node1.sent
|
||||
@@ -187,9 +187,9 @@ class TestLoadScheduling:
|
||||
node = MockNode()
|
||||
config = testdir.parseconfig("--tx=popen")
|
||||
sched = LoadScheduling(config)
|
||||
sched.addnode(node)
|
||||
sched.add_node(node)
|
||||
collection = ["test_file.py::test_func"]
|
||||
sched.addnode_collection(node, collection)
|
||||
sched.add_node_collection(node, collection)
|
||||
assert sched.collection_is_completed
|
||||
sched.schedule()
|
||||
assert not sched.pending
|
||||
@@ -219,10 +219,10 @@ class TestLoadScheduling:
|
||||
node1 = MockNode()
|
||||
node2 = MockNode()
|
||||
sched = LoadScheduling(config)
|
||||
sched.addnode(node1)
|
||||
sched.addnode(node2)
|
||||
sched.addnode_collection(node1, ["a.py::test_1"])
|
||||
sched.addnode_collection(node2, ["a.py::test_2"])
|
||||
sched.add_node(node1)
|
||||
sched.add_node(node2)
|
||||
sched.add_node_collection(node1, ["a.py::test_1"])
|
||||
sched.add_node_collection(node2, ["a.py::test_2"])
|
||||
sched.schedule()
|
||||
assert len(collect_hook.reports) == 1
|
||||
rep = collect_hook.reports[0]
|
||||
|
||||
@@ -42,10 +42,10 @@ class EachScheduling:
|
||||
"""A list of all nodes in the scheduler."""
|
||||
return list(self.node2pending.keys())
|
||||
|
||||
def hasnodes(self):
|
||||
def has_nodes(self):
|
||||
return bool(self.node2pending)
|
||||
|
||||
def haspending(self):
|
||||
def has_pending(self):
|
||||
"""Return True if there are pending test items
|
||||
|
||||
This indicates that collection has finished and nodes are
|
||||
@@ -57,7 +57,7 @@ class EachScheduling:
|
||||
return True
|
||||
return False
|
||||
|
||||
def addnode(self, node):
|
||||
def add_node(self, node):
|
||||
assert node not in self.node2pending
|
||||
self.node2pending[node] = []
|
||||
|
||||
@@ -71,7 +71,7 @@ class EachScheduling:
|
||||
return False
|
||||
return True
|
||||
|
||||
def addnode_collection(self, node, collection):
|
||||
def add_node_collection(self, node, collection):
|
||||
"""Add the collected test items from a node
|
||||
|
||||
Collection is complete once all nodes have submitted their
|
||||
@@ -107,7 +107,7 @@ class EachScheduling:
|
||||
self.node2pending[node].remove(item_index)
|
||||
|
||||
def remove_node(self, node):
|
||||
# KeyError if we didn't get an addnode() yet
|
||||
# KeyError if we didn't get an add_node() yet
|
||||
pending = self.node2pending.pop(node)
|
||||
if not pending:
|
||||
return
|
||||
@@ -121,7 +121,7 @@ class EachScheduling:
|
||||
|
||||
If the node's pending list is empty it is a new node which
|
||||
needs to run all the tests. If the pending list is already
|
||||
populated (by ``.addnode_collection()``) then it replaces a
|
||||
populated (by ``.add_node_collection()``) then it replaces a
|
||||
dead node and we only need to run those tests.
|
||||
"""
|
||||
assert self.collection_is_completed
|
||||
@@ -209,7 +209,7 @@ class LoadScheduling:
|
||||
"""
|
||||
return len(self.node2collection) >= self.numnodes
|
||||
|
||||
def haspending(self):
|
||||
def has_pending(self):
|
||||
"""Return True if there are pending test items
|
||||
|
||||
This indicates that collection has finished and nodes are
|
||||
@@ -223,11 +223,11 @@ class LoadScheduling:
|
||||
return True
|
||||
return False
|
||||
|
||||
def hasnodes(self):
|
||||
def has_nodes(self):
|
||||
"""Return True if nodes exist in the scheduler."""
|
||||
return bool(self.node2pending)
|
||||
|
||||
def addnode(self, node):
|
||||
def add_node(self, node):
|
||||
"""Add a new node to the scheduler.
|
||||
|
||||
From now on the node will be allocated chunks of tests to
|
||||
@@ -250,7 +250,7 @@ class LoadScheduling:
|
||||
return False
|
||||
return True
|
||||
|
||||
def addnode_collection(self, node, collection):
|
||||
def add_node_collection(self, node, collection):
|
||||
"""Add the collected test items from a node
|
||||
|
||||
The collection is stored in the ``.node2collection`` map.
|
||||
@@ -579,7 +579,7 @@ class DSession:
|
||||
if self.shuttingdown:
|
||||
node.shutdown()
|
||||
else:
|
||||
self.sched.addnode(node)
|
||||
self.sched.add_node(node)
|
||||
|
||||
def slave_slavefinished(self, node):
|
||||
"""Emitted when node executes its pytest_sessionfinish hook.
|
||||
@@ -641,11 +641,11 @@ class DSession:
|
||||
# tell session which items were effectively collected otherwise
|
||||
# the master node will finish the session with EXIT_NOTESTSCOLLECTED
|
||||
self._session.testscollected = len(ids)
|
||||
self.sched.addnode_collection(node, ids)
|
||||
self.sched.add_node_collection(node, ids)
|
||||
if self.terminal:
|
||||
self.trdist.setstatus(node.gateway.spec, "[%d]" % (len(ids)))
|
||||
if self.sched.collection_is_completed:
|
||||
if self.terminal and not self.sched.haspending():
|
||||
if self.terminal and not self.sched.has_pending():
|
||||
self.trdist.ensure_show_status()
|
||||
self.terminal.write_line("")
|
||||
self.terminal.write_line("scheduling tests via %s" % (
|
||||
|
||||
Reference in New Issue
Block a user