[pypy-commit] pypy stm: Add a test and, for now, fix the emulation to match the real code's

arigo noreply at buildbot.pypy.org
Tue Jan 31 16:07:17 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51992:2cbc49a8a169
Date: 2012-01-31 16:06 +0100
http://bitbucket.org/pypy/pypy/changeset/2cbc49a8a169/

Log:	Add a test and, for now, fix the emulation to match the real code's
	behavior. Maybe at some point we want instead the opposite
	behavior, but it's unclear.

diff --git a/lib_pypy/transaction.py b/lib_pypy/transaction.py
--- a/lib_pypy/transaction.py
+++ b/lib_pypy/transaction.py
@@ -30,6 +30,9 @@
 
 def run():
     pending = _pending
-    while pending:
-        _, (f, args) = pending.popitem()
-        f(*args)
+    try:
+        while pending:
+            _, (f, args) = pending.popitem()
+            f(*args)
+    finally:
+        pending.clear()   # this is the behavior we get with interp_transaction
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
@@ -60,6 +60,21 @@
         assert len(lst) == 1
         assert lst[0] == e.args[0]
 
+    def test_clear_pending_transactions(self):
+        import transaction
+        class Foo(Exception):
+            pass
+        def raiseme():
+            raise Foo
+        for i in range(20):
+            transaction.add(raiseme)
+        try:
+            transaction.run()
+            assert 0, "should have raised Foo"
+        except Foo:
+            pass
+        transaction.run()   # all the other 'raiseme's should have been cleared
+
 
 class AppTestTransactionEmulator(AppTestTransaction):
     def setup_class(cls):


More information about the pypy-commit mailing list