[py-svn] r57127 - in py/branch/event/py/test2/rsession: . testing
hpk at codespeak.net
hpk at codespeak.net
Sat Aug 9 12:57:50 CEST 2008
Author: hpk
Date: Sat Aug 9 12:57:48 2008
New Revision: 57127
Modified:
py/branch/event/py/test2/rsession/hostmanage.py
py/branch/event/py/test2/rsession/masterslave.py
py/branch/event/py/test2/rsession/testing/test_masterslave.py
Log:
implement sendlist, shutdown, remove uneeded tests
Modified: py/branch/event/py/test2/rsession/hostmanage.py
==============================================================================
--- py/branch/event/py/test2/rsession/hostmanage.py (original)
+++ py/branch/event/py/test2/rsession/hostmanage.py Sat Aug 9 12:57:48 2008
@@ -170,7 +170,7 @@
if host not in pending_going_down:
if not host.node.pending:
# reschedule tests
- host.node.send(None)
+ host.node.shutdown()
pending_going_down.append(host)
else:
numitems += len(host.node.pending)
Modified: py/branch/event/py/test2/rsession/masterslave.py
==============================================================================
--- py/branch/event/py/test2/rsession/masterslave.py (original)
+++ py/branch/event/py/test2/rsession/masterslave.py Sat Aug 9 12:57:48 2008
@@ -52,23 +52,26 @@
self.notify(ev)
def send(self, item):
+ assert item is not None
self.channel.send(item)
- if item is not None:
- self.pending.append(item)
- self.notify(repevent.SendItem(self.host, item))
+ self.pending.append(item)
+
+ def sendlist(self, itemlist):
+ self.channel.send(itemlist)
+ self.pending.extend(itemlist)
+
+ def shutdown(self):
+ self.channel.send(None)
#
-# config objects need to be exchanged and unified between
-# two sides so that collectors and items referencing the
-# config will be regarded equal - and also for an item
-# to be reconstructed by its names.
-#
+# a config needs to be available on the other side for options
+# and for reconstructing collection trees (topdir, conftest access)
#
def send_and_receive_pickled_config(channel, config, remote_topdir):
channel.send((config, remote_topdir))
backconfig = channel.receive()
- assert config is backconfig
+ assert config is backconfig # ImmutablePickling :)
return backconfig
def receive_and_send_pickled_config(channel):
@@ -102,10 +105,17 @@
nice_level = config.getvalue('dist_nicelevel')
os.nice(nice_level)
while 1:
- item = channel.receive()
- if item is None:
+ task = channel.receive()
+ if task is None: # shutdown
channel.send(None)
break
- runner = item._getrunner()
- testrep = runner(item)
- channel.send(testrep)
+ if isinstance(task, list):
+ for item in task:
+ runtest(channel, item)
+ else:
+ runtest(channel, task)
+
+def runtest(channel, item):
+ runner = item._getrunner()
+ testrep = runner(item)
+ channel.send(testrep)
Modified: py/branch/event/py/test2/rsession/testing/test_masterslave.py
==============================================================================
--- py/branch/event/py/test2/rsession/testing/test_masterslave.py (original)
+++ py/branch/event/py/test2/rsession/testing/test_masterslave.py Sat Aug 9 12:57:48 2008
@@ -1,55 +1,10 @@
import py
-from py.__.test2.rsession.masterslave import (
- MasterNode, send_and_receive_pickled_config,
- receive_and_send_pickled_config
-)
+from py.__.test2.rsession.masterslave import MasterNode
from py.__.test2.rsession.hostmanage import Host
from basetest import BasicRsessionTest
from py.__.test2 import repevent
-
-def xxxtest_receive_config():
- from cPickle import dumps, loads
- l = []
- class MyChannel:
- def receive(self):
- return loads(l.pop())
- def send(self, arg):
- l.append(dumps(arg))
-
- channel = MyChannel()
- config = py.test2.config._reparse([])
- topdir = py.test.ensuretemp("test_send_receive_config")
- channel.send((config, topdir))
- newconfig = receive_and_send_pickled_config(channel)
- assert newconfig.topdir == topdir
- backconfig = channel.receive()
- assert not backconfig._initialized
-
-def xxxtest_send_config():
- from cPickle import dumps, loads
- l = []
- class MyChannel:
- def receive(self):
- return loads(l.pop(0))
- def send(self, arg):
- l.append(dumps(arg))
-
- channel = MyChannel()
- config = py.test2.config._reparse([])
- topdir = py.test.ensuretemp("test_send_config")
- channel.send(config)
- newconfig = send_and_receive_pickled_config(channel, config, topdir)
-
- assert newconfig.topdir == config.topdir
- assert newconfig.args == config.args
- #assert newconfig.option == config.option
-
- backconfig,newtopdir = channel.receive()
- assert not backconfig._initialized
- assert newtopdir == topdir
-
class TestMasterSlaveConnection(BasicRsessionTest):
def getevent(self, eventtype=repevent.ItemTestReport, timeout=2.0):
events = []
@@ -69,16 +24,15 @@
def setup_method(self, method):
super(TestMasterSlaveConnection, self).setup_method(method)
self.queue = py.std.Queue.Queue()
- self.session.bus.subscribe(self.queue.put)
self.host = Host("localhost")
self.host.initgateway()
self.node = MasterNode(self.host, self.session.config,
- self.session.bus.notify)
+ self.queue.put)
assert not self.node.channel.isclosed()
def teardown_method(self, method):
print "at teardown:", self.node.channel
- self.session.bus.unsubscribe(self.queue.put)
+ self.host.gw.exit()
def test_crash_invalid_item(self):
self.node.send(123) # invalid item
@@ -96,7 +50,7 @@
assert str(ev.error).find("TERMINATED") != -1
def test_node_down(self):
- self.node.send(None)
+ self.node.shutdown()
event = self.getevent(repevent.HostDown)
assert event.host == self.host
assert event.pending == []
@@ -122,9 +76,19 @@
#assert event.item == item
#assert event.item is not item
- def test_send_multiple(self):
+ def test_send_some(self):
for outcome in "passed failed skipped".split():
self.node.send(self.getfunc(outcome))
ev = self.getevent()
assert getattr(ev, outcome)
assert not self.node.pending
+
+ def test_send_list(self):
+ l = []
+ for outcome in "passed failed skipped".split():
+ l.append(self.getfunc(outcome))
+ self.node.sendlist(l)
+ for outcome in "passed failed skipped".split():
+ ev = self.getevent()
+ assert getattr(ev, outcome)
+ assert not self.node.pending
More information about the pytest-commit
mailing list