Commits

Armin Rigo  committed 2cbc49a

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.

  • Participants
  • Parent commits cbf4aa8
  • Branches stm

Comments (0)

Files changed (2)

File lib_pypy/transaction.py

 
 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

File pypy/module/transaction/test/test_transaction.py

         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):