[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:
hpk 2007-02-05 00:12:12 +01:00
parent 0292420920
commit e8bdb867fa
4 changed files with 23 additions and 58 deletions

View File

@ -124,19 +124,17 @@ class HostManager(object):
finishedcallback=donecallback) finishedcallback=donecallback)
rsync.send(root) rsync.send(root)
def init_hosts(self, reporter, done_dict=None): def init_hosts(self, reporter):
if done_dict is None:
done_dict = {}
# hosts ready # hosts ready
self.init_rsync(reporter) 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 = [] nodes = []
for host in self.sshhosts: for host in self.sshhosts:
if hasattr(host.gw, 'remote_exec'): # otherwise dummy for tests :/ if hasattr(host.gw, 'remote_exec'): # otherwise dummy for tests :/
ch = setup_slave(host, self.config) ch = setup_slave(host, self.config)
nodes.append(MasterNode(ch, reporter, done_dict)) nodes.append(MasterNode(ch, reporter))
return nodes return nodes
def teardown_hosts(self, reporter, channels, nodes, def teardown_hosts(self, reporter, channels, nodes,

View File

@ -6,17 +6,15 @@ from py.__.test.rsession.outcome import ReprOutcome
from py.__.test.rsession import report from py.__.test.rsession import report
class MasterNode(object): class MasterNode(object):
def __init__(self, channel, reporter, done_dict): def __init__(self, channel, reporter):
self.channel = channel self.channel = channel
self.reporter = reporter 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 = [] 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): def receive_result(self, outcomestring, item):
repr_outcome = ReprOutcome(outcomestring) 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): for y in x._tryiter(reporterror = lambda x: reporterror(reporter, x), keyword = keyword):
yield y 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, def dispatch_loop(masternodes, itemgenerator, shouldstop,
waiter = lambda: py.std.time.sleep(0.1), waiter = lambda: py.std.time.sleep(0.1),
max_tasks_per_node=None): max_tasks_per_node=None):

View File

@ -9,8 +9,7 @@ import re
import time import time
from py.__.test.rsession import report from py.__.test.rsession import report
from py.__.test.rsession.master import \ from py.__.test.rsession.master import MasterNode, dispatch_loop, itemgen
MasterNode, dispatch_loop, itemgen, randomgen
from py.__.test.rsession.hostmanage import HostInfo, HostManager from py.__.test.rsession.hostmanage import HostInfo, HostManager
from py.__.test.rsession.local import local_loop, plain_runner, apigen_runner,\ from py.__.test.rsession.local import local_loop, plain_runner, apigen_runner,\
box_runner box_runner
@ -133,13 +132,12 @@ class RSession(AbstractSession):
reporter(report.TestStarted(sshhosts)) reporter(report.TestStarted(sshhosts))
done_dict = {}
hostmanager = HostManager(sshhosts, self.config) hostmanager = HostManager(sshhosts, self.config)
try: try:
nodes = hostmanager.init_hosts(reporter, done_dict) nodes = hostmanager.init_hosts(reporter)
reporter(report.RsyncFinished()) reporter(report.RsyncFinished())
try: try:
self.dispatch_tests(nodes, reporter, checkfun, done_dict) self.dispatch_tests(nodes, reporter, checkfun)
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
print >>sys.stderr, "C-c pressed waiting for gateways to teardown..." print >>sys.stderr, "C-c pressed waiting for gateways to teardown..."
channels = [node.channel for node in nodes] channels = [node.channel for node in nodes]
@ -168,20 +166,12 @@ class RSession(AbstractSession):
return [HostInfo(spec) for spec in return [HostInfo(spec) for spec in
self.config.getvalue("dist_hosts")] 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() colitems = self.config.getcolitems()
keyword = self.config.option.keyword keyword = self.config.option.keyword
itemgenerator = itemgen(colitems, reporter, keyword, self.reporterror) itemgenerator = itemgen(colitems, reporter, keyword, self.reporterror)
all_tests = dispatch_loop(nodes, itemgenerator, checkfun) 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): class LSession(AbstractSession):
""" Local version of session """ Local version of session

View File

@ -9,7 +9,7 @@ import py, sys
if sys.platform == 'win32': if sys.platform == 'win32':
py.test.skip("rsession is unsupported on Windows.") 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.slave import setup_slave
from py.__.test.rsession.outcome import ReprOutcome, Outcome from py.__.test.rsession.outcome import ReprOutcome, Outcome
from py.__.test.rsession import report from py.__.test.rsession import report
@ -51,7 +51,7 @@ def test_masternode():
ch = DummyChannel() ch = DummyChannel()
reportlist = [] reportlist = []
mnode = MasterNode(ch, reportlist.append, {}) mnode = MasterNode(ch, reportlist.append)
mnode.send(Item("ok")) mnode.send(Item("ok"))
mnode.send(Item("notok")) mnode.send(Item("notok"))
ch.callback(Outcome().make_repr()) ch.callback(Outcome().make_repr())
@ -62,15 +62,19 @@ def test_masternode():
assert received[0].outcome.passed assert received[0].outcome.passed
assert not received[1].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() ch = DummyChannel()
reportlist = [] reportlist = []
mnode = MasterNode(ch, reportlist.append, {}) mnode = MasterNode(ch, reportlist.append)
mnode.send(Item("ok")) mnode.send(Item("ok"))
mnode.send(Item("ok")) mnode.send(Item("ok"))
ch.callback(Outcome().make_repr()) ch.callback(Outcome().make_repr())
ch.callback(Outcome().make_repr()) ch.callback(Outcome().make_repr())
assert len(reportlist) == 3 assert len(reportlist) == 4
def test_outcome_repr(): def test_outcome_repr():
out = ReprOutcome(Outcome(skipped=True).make_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 # XXX: We have to wait here a bit to make sure that it really did happen
channel.waitclose(2) 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()")