[py-svn] r57150 - in py/branch/event/py/test2: . dist dist/testing
hpk at codespeak.net
hpk at codespeak.net
Sat Aug 9 20:22:27 CEST 2008
Author: hpk
Date: Sat Aug 9 20:22:27 2008
New Revision: 57150
Modified:
py/branch/event/py/test2/dist/async.py
py/branch/event/py/test2/dist/testing/test_async.py
py/branch/event/py/test2/repevent.py
Log:
fix busy waiting issue (hopefully)
Modified: py/branch/event/py/test2/dist/async.py
==============================================================================
--- py/branch/event/py/test2/dist/async.py (original)
+++ py/branch/event/py/test2/dist/async.py Sat Aug 9 20:22:27 2008
@@ -64,11 +64,13 @@
def loop(self, colitems):
exitstatus = self.EXIT_OK
try:
+ wait_for_event = False
while 1:
- if colitems:
- self.triggertesting(colitems)
+ if not wait_for_event and colitems:
+ self.triggertesting(colitems)
colitems = []
ev = self.queue.get()
+ wait_for_event = False
self.bus.notify(ev)
if isinstance(ev, repevent.HostDown):
self.handle_hostdown(ev)
@@ -76,7 +78,8 @@
if not self.hosts:
exitstatus = self.EXIT_NOHOSTS
break
- self.reschedule(ev.items)
+ colitems.extend(ev.items)
+ wait_for_event = True
elif isinstance(ev, repevent.ItemTestReport):
all_completed = self.processresult(ev)
if all_completed:
@@ -84,12 +87,13 @@
break
elif isinstance(ev, repevent.CollectionReport):
if ev.passed:
- colitems = ev.result
+ colitems.extend(ev.result)
except KeyboardInterrupt:
#print py.code.ExceptionInfo().getrepr(funcargs=True)
#raise
exitstatus = self.EXIT_INTERRUPTED
except:
+ #raise
self.bus.notify(repevent.InternalException())
exitstatus = self.EXIT_INTERNALERROR
if exitstatus == 0 and self._testsfailed:
@@ -160,10 +164,7 @@
def handle_hostdown(self, ev):
pending = self.removehost(ev.host)
- self.reschedule(pending)
-
- def reschedule(self, items):
- self.sendtestitems(items)
+ self.queue.put(repevent.RescheduleItems(pending))
def sendtestitems(self, tosend):
for host, pending in self.host2pending.items():
Modified: py/branch/event/py/test2/dist/testing/test_async.py
==============================================================================
--- py/branch/event/py/test2/dist/testing/test_async.py (original)
+++ py/branch/event/py/test2/dist/testing/test_async.py Sat Aug 9 20:22:27 2008
@@ -103,8 +103,10 @@
session.addhost(host1)
ev = repevent.RescheduleItems([item])
session.queue.put(ev)
+ session.queue.put(repevent.NOP())
session.queue.put(run(item))
exitstatus = session.loop([])
+ dumpqueue(session.queue)
assert exitstatus == session.EXIT_OK
assert host1.node.sent == [[item]]
@@ -158,14 +160,24 @@
host1.node = MockNode()
session.addhost(host1)
items = basic_collect_report(modcol).result
+
+ # trigger testing - this sends tests to host1
session.triggertesting(items)
+
+ # run tests ourselves and produce reports
ev1 = run(items[0])
ev2 = run(items[1])
session.queue.put(ev1)
session.queue.put(ev2)
+
+ # now call the loop
exitstatus = session.loop([])
+
+ # and see that it only looked for one result
assert session.queue.qsize() == 1
dumpqueue(session.queue)
+
+ # and exits properly
assert exitstatus == session.EXIT_TESTSFAILED
def test_dselected(self):
@@ -193,3 +205,36 @@
ev = session.queue.get(block=False)
assert isinstance(ev, repevent.Deselected)
assert ev.items == [items[1]]
+
+
+ def test_no_busy_reschedule_items(self):
+ item = self.getitem("def test_func(): 0/0")
+ session = AsyncSession(item._config)
+
+ # set up a host that is full of pending items
+ host = Host("localhost")
+ host.node = MockNode()
+ session.addhost(host)
+ session.host2pending[host].extend([item] * session.MAXITEMSPERHOST)
+
+ # check that the loop does not busy wait
+ # i.e. puts a RescheduleEvent into the queue
+ # just after having read one and finding no
+ # place to distribute tests to
+ events = [repevent.RescheduleItems([item])]
+ def mocked_queue_get():
+ return events.pop()
+ oldget = session.queue.get
+ session.queue.get = mocked_queue_get
+ exitstatus = session.loop([])
+ assert not session.queue.qsize(), oldget()
+
+ def test_initial_reschedule(self):
+ item = self.getitem("def test_func(): 0/0")
+ session = AsyncSession(item._config)
+
+ # set up a host that is full of pending items
+ host = Host("localhost")
+ host.node = MockNode()
+ session.addhost(host)
+ session.host2pending[host].extend([item] * session.MAXITEMSPERHOST)
Modified: py/branch/event/py/test2/repevent.py
==============================================================================
--- py/branch/event/py/test2/repevent.py (original)
+++ py/branch/event/py/test2/repevent.py Sat Aug 9 20:22:27 2008
@@ -19,6 +19,9 @@
def timestamp():
return time.time()
+class NOP(BaseEvent):
+ pass
+
# ----------------------------------------------------------------------
# Basic Live Reporting Events
# ----------------------------------------------------------------------
More information about the pytest-commit
mailing list