[pypy-commit] pypy stm: (bivab, arigo)
arigo
noreply at buildbot.pypy.org
Thu Jan 19 18:00:14 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51490:601a7695b552
Date: 2012-01-19 16:41 +0100
http://bitbucket.org/pypy/pypy/changeset/601a7695b552/
Log: (bivab, arigo)
A failing test.
diff --git a/pypy/module/transaction/interp_transaction.py b/pypy/module/transaction/interp_transaction.py
--- a/pypy/module/transaction/interp_transaction.py
+++ b/pypy/module/transaction/interp_transaction.py
@@ -97,7 +97,6 @@
state.num_waiting_threads += 1
if state.num_waiting_threads == state.num_threads:
state.finished = True
- state.unlock_unfinished()
state.unlock_no_tasks_pending()
state.unlock()
#
@@ -105,9 +104,9 @@
state.unlock_no_tasks_pending()
#
state.lock()
+ state.num_waiting_threads -= 1
if state.finished:
break
- state.num_waiting_threads -= 1
else:
pending = state.pending.pop(0)
if len(state.pending) == 0:
@@ -116,6 +115,8 @@
pending.run()
state.lock()
#
+ if state.num_waiting_threads == 0: # only the last thread to leave
+ state.unlock_unfinished()
state.unlock()
@@ -132,7 +133,7 @@
threadintf.start_new_thread(_run_thread, ())
#
state.lock_unfinished()
- assert state.num_waiting_threads == state.num_threads
+ assert state.num_waiting_threads == 0
assert len(state.pending) == 0
state.lock_no_tasks_pending()
state.running = False
diff --git a/pypy/module/transaction/test/test_interp_transaction.py b/pypy/module/transaction/test/test_interp_transaction.py
--- a/pypy/module/transaction/test/test_interp_transaction.py
+++ b/pypy/module/transaction/test/test_interp_transaction.py
@@ -1,3 +1,4 @@
+import time
from pypy.module.transaction import interp_transaction
@@ -22,3 +23,49 @@
assert seen == []
interp_transaction.run(space)
assert seen == range(201)
+
+
+def test_tree_of_transactions():
+ space = FakeSpace()
+ interp_transaction.state.startup(space)
+ seen = []
+ #
+ def do(level):
+ seen.append(level)
+ if level < 11:
+ interp_transaction.add(space, do, (level+1,))
+ interp_transaction.add(space, do, (level+1,))
+ #
+ interp_transaction.add(space, do, (0,))
+ assert seen == []
+ interp_transaction.run(space)
+ for i in range(12):
+ assert seen.count(i) == 2 ** i
+ assert len(seen) == 2 ** 12 - 1
+
+
+def test_transactional_simple():
+ space = FakeSpace()
+ interp_transaction.state.startup(space)
+ lst = []
+ def f(n):
+ lst.append(n+0)
+ lst.append(n+1)
+ time.sleep(0.05)
+ lst.append(n+2)
+ lst.append(n+3)
+ lst.append(n+4)
+ time.sleep(0.25)
+ lst.append(n+5)
+ lst.append(n+6)
+ interp_transaction.add(space, f, (10,))
+ interp_transaction.add(space, f, (20,))
+ interp_transaction.add(space, f, (30,))
+ interp_transaction.run(space)
+ assert len(lst) == 7 * 3
+ seen = set()
+ for start in range(0, 21, 7):
+ seen.add(lst[start])
+ for index in range(7):
+ assert lst[start + index] == lst[start] + index
+ assert seen == set([10, 20, 30])
diff --git a/pypy/module/transaction/test/test_transaction.py b/pypy/module/transaction/test/test_transaction.py
--- a/pypy/module/transaction/test/test_transaction.py
+++ b/pypy/module/transaction/test/test_transaction.py
@@ -4,6 +4,7 @@
class AppTestTransaction:
def setup_class(cls):
+ py.test.skip("XXX not transactional!")
cls.space = gettestobjspace(usemodules=['transaction'])
def test_simple(self):
@@ -14,3 +15,26 @@
transaction.add(lst.append, 7)
transaction.run()
assert sorted(lst) == [5, 6, 7]
+
+ def test_almost_as_simple(self):
+ import transaction
+ lst = []
+ def f(n):
+ lst.append(n+0)
+ lst.append(n+1)
+ lst.append(n+2)
+ lst.append(n+3)
+ lst.append(n+4)
+ lst.append(n+5)
+ lst.append(n+6)
+ transaction.add(f, 10)
+ transaction.add(f, 20)
+ transaction.add(f, 30)
+ transaction.run()
+ assert len(lst) == 7 * 3
+ seen = set()
+ for start in range(0, 21, 7):
+ seen.append(lst[start])
+ for index in range(7):
+ assert lst[start + index] == lst[start] + index
+ assert seen == set([10, 20, 30])
More information about the pypy-commit
mailing list