[svn r37935] remove done_dict and according experimental
code for re-scheduling (i guess) fijal: in the diff you'll find a XXX fijal, i changed the meaning of a test, wasn't sure about it. can you check? --HG-- branch : trunk
This commit is contained in:
parent
0292420920
commit
e8bdb867fa
|
@ -124,19 +124,17 @@ class HostManager(object):
|
|||
finishedcallback=donecallback)
|
||||
rsync.send(root)
|
||||
|
||||
def init_hosts(self, reporter, done_dict=None):
|
||||
if done_dict is None:
|
||||
done_dict = {}
|
||||
def init_hosts(self, reporter):
|
||||
# hosts ready
|
||||
self.init_rsync(reporter)
|
||||
return self.setup_nodes(reporter, done_dict)
|
||||
return self.setup_nodes(reporter)
|
||||
|
||||
def setup_nodes(self, reporter, done_dict):
|
||||
def setup_nodes(self, reporter):
|
||||
nodes = []
|
||||
for host in self.sshhosts:
|
||||
if hasattr(host.gw, 'remote_exec'): # otherwise dummy for tests :/
|
||||
ch = setup_slave(host, self.config)
|
||||
nodes.append(MasterNode(ch, reporter, done_dict))
|
||||
nodes.append(MasterNode(ch, reporter))
|
||||
return nodes
|
||||
|
||||
def teardown_hosts(self, reporter, channels, nodes,
|
||||
|
|
|
@ -6,17 +6,15 @@ from py.__.test.rsession.outcome import ReprOutcome
|
|||
from py.__.test.rsession import report
|
||||
|
||||
class MasterNode(object):
|
||||
def __init__(self, channel, reporter, done_dict):
|
||||
def __init__(self, channel, reporter):
|
||||
self.channel = channel
|
||||
self.reporter = reporter
|
||||
|
||||
def callback(outcome):
|
||||
item = self.pending.pop()
|
||||
if not item in done_dict:
|
||||
self.receive_result(outcome, item)
|
||||
done_dict[item] = True
|
||||
channel.setcallback(callback)
|
||||
self.pending = []
|
||||
channel.setcallback(self._callback)
|
||||
|
||||
def _callback(self, outcome):
|
||||
item = self.pending.pop()
|
||||
self.receive_result(outcome, item)
|
||||
|
||||
def receive_result(self, outcomestring, item):
|
||||
repr_outcome = ReprOutcome(outcomestring)
|
||||
|
@ -39,19 +37,6 @@ def itemgen(colitems, reporter, keyword, reporterror):
|
|||
for y in x._tryiter(reporterror = lambda x: reporterror(reporter, x), keyword = keyword):
|
||||
yield y
|
||||
|
||||
def randomgen(items, done_dict):
|
||||
""" Generator, which randomly gets all the tests from items as long
|
||||
as they're not in done_dict
|
||||
"""
|
||||
import random
|
||||
while items:
|
||||
values = items.keys()
|
||||
item = values[int(random.random()*len(values))]
|
||||
if item in done_dict:
|
||||
del items[item]
|
||||
else:
|
||||
yield item
|
||||
|
||||
def dispatch_loop(masternodes, itemgenerator, shouldstop,
|
||||
waiter = lambda: py.std.time.sleep(0.1),
|
||||
max_tasks_per_node=None):
|
||||
|
|
|
@ -9,8 +9,7 @@ import re
|
|||
import time
|
||||
|
||||
from py.__.test.rsession import report
|
||||
from py.__.test.rsession.master import \
|
||||
MasterNode, dispatch_loop, itemgen, randomgen
|
||||
from py.__.test.rsession.master import MasterNode, dispatch_loop, itemgen
|
||||
from py.__.test.rsession.hostmanage import HostInfo, HostManager
|
||||
from py.__.test.rsession.local import local_loop, plain_runner, apigen_runner,\
|
||||
box_runner
|
||||
|
@ -133,13 +132,12 @@ class RSession(AbstractSession):
|
|||
|
||||
reporter(report.TestStarted(sshhosts))
|
||||
|
||||
done_dict = {}
|
||||
hostmanager = HostManager(sshhosts, self.config)
|
||||
try:
|
||||
nodes = hostmanager.init_hosts(reporter, done_dict)
|
||||
nodes = hostmanager.init_hosts(reporter)
|
||||
reporter(report.RsyncFinished())
|
||||
try:
|
||||
self.dispatch_tests(nodes, reporter, checkfun, done_dict)
|
||||
self.dispatch_tests(nodes, reporter, checkfun)
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
print >>sys.stderr, "C-c pressed waiting for gateways to teardown..."
|
||||
channels = [node.channel for node in nodes]
|
||||
|
@ -168,20 +166,12 @@ class RSession(AbstractSession):
|
|||
return [HostInfo(spec) for spec in
|
||||
self.config.getvalue("dist_hosts")]
|
||||
|
||||
def dispatch_tests(self, nodes, reporter, checkfun, done_dict):
|
||||
def dispatch_tests(self, nodes, reporter, checkfun):
|
||||
colitems = self.config.getcolitems()
|
||||
keyword = self.config.option.keyword
|
||||
itemgenerator = itemgen(colitems, reporter, keyword, self.reporterror)
|
||||
|
||||
all_tests = dispatch_loop(nodes, itemgenerator, checkfun)
|
||||
#if all_tests:
|
||||
# todo = {}
|
||||
# for key, value in all_tests.items():
|
||||
# if key not in done_dict:
|
||||
# todo[key] = True
|
||||
# rg = randomgen(todo, done_dict)
|
||||
# dispatch_loop(nodes, rg, lambda:False, max_tasks_per_node=1)
|
||||
|
||||
|
||||
class LSession(AbstractSession):
|
||||
""" Local version of session
|
||||
|
|
|
@ -9,7 +9,7 @@ import py, sys
|
|||
if sys.platform == 'win32':
|
||||
py.test.skip("rsession is unsupported on Windows.")
|
||||
|
||||
from py.__.test.rsession.master import dispatch_loop, MasterNode, randomgen
|
||||
from py.__.test.rsession.master import dispatch_loop, MasterNode
|
||||
from py.__.test.rsession.slave import setup_slave
|
||||
from py.__.test.rsession.outcome import ReprOutcome, Outcome
|
||||
from py.__.test.rsession import report
|
||||
|
@ -51,7 +51,7 @@ def test_masternode():
|
|||
|
||||
ch = DummyChannel()
|
||||
reportlist = []
|
||||
mnode = MasterNode(ch, reportlist.append, {})
|
||||
mnode = MasterNode(ch, reportlist.append)
|
||||
mnode.send(Item("ok"))
|
||||
mnode.send(Item("notok"))
|
||||
ch.callback(Outcome().make_repr())
|
||||
|
@ -62,15 +62,19 @@ def test_masternode():
|
|||
assert received[0].outcome.passed
|
||||
assert not received[1].outcome.passed
|
||||
|
||||
def test_unique_nodes():
|
||||
def test_sending_two_noes():
|
||||
# XXX fijal: this test previously tested that the second
|
||||
# item result would not get send. why? did i miss
|
||||
# something?
|
||||
#
|
||||
ch = DummyChannel()
|
||||
reportlist = []
|
||||
mnode = MasterNode(ch, reportlist.append, {})
|
||||
mnode = MasterNode(ch, reportlist.append)
|
||||
mnode.send(Item("ok"))
|
||||
mnode.send(Item("ok"))
|
||||
ch.callback(Outcome().make_repr())
|
||||
ch.callback(Outcome().make_repr())
|
||||
assert len(reportlist) == 3
|
||||
assert len(reportlist) == 4
|
||||
|
||||
def test_outcome_repr():
|
||||
out = ReprOutcome(Outcome(skipped=True).make_repr())
|
||||
|
@ -184,15 +188,3 @@ def test_slave_running_interrupted():
|
|||
# XXX: We have to wait here a bit to make sure that it really did happen
|
||||
channel.waitclose(2)
|
||||
|
||||
def test_randomgen():
|
||||
d = {}
|
||||
gen = randomgen({1:True, 2:True, 3:True}, d)
|
||||
for i in range(100):
|
||||
assert gen.next() in [1,2,3]
|
||||
d[3] = True
|
||||
for i in range(100):
|
||||
assert gen.next() in [1,2]
|
||||
d[2] = True
|
||||
d[1] = True
|
||||
py.test.raises(StopIteration, "gen.next()")
|
||||
|
||||
|
|
Loading…
Reference in New Issue