From 98b996b4da8583f17622c3021a97609aaf8845a5 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Sat, 28 Aug 2010 06:34:32 +0000
Subject: [PATCH] Duplicate tpc_begin calls should raise.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2246 71dcc9de-d417-0410-9af5-da40c76e7ee4
---
 neo/client/app.py                 | 2 +-
 neo/tests/client/testClientApp.py | 7 ++-----
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/neo/client/app.py b/neo/client/app.py
index 26e49d34..90a725df 100644
--- a/neo/client/app.py
+++ b/neo/client/app.py
@@ -556,7 +556,7 @@ class Application(object):
         # First get a transaction, only one is allowed at a time
         if self.local_var.txn is transaction:
             # We already begin the same transaction
-            return
+            raise StorageTransactionError('Duplicate tpc_begin calls')
         if self.local_var.txn is not None:
             raise NeoException, 'local_var is not clean in tpc_begin'
         # use the given TID or request a new one to the master
diff --git a/neo/tests/client/testClientApp.py b/neo/tests/client/testClientApp.py
index 54f0d985..2ed74b07 100644
--- a/neo/tests/client/testClientApp.py
+++ b/neo/tests/client/testClientApp.py
@@ -384,7 +384,8 @@ class ClientApplicationTests(NeoTestBase):
         self.assertTrue(app.local_var.txn is txn)
         self.assertEquals(app.local_var.tid, tid)
         # next, the transaction already begin -> do nothing
-        app.tpc_begin(transaction=txn, tid=None)
+        self.assertRaises(StorageTransactionError, app.tpc_begin,
+            transaction=txn, tid=None)
         self.assertTrue(app.local_var.txn is txn)
         self.assertEquals(app.local_var.tid, tid)
         # cancel and start a transaction without tid
@@ -534,7 +535,6 @@ class ClientApplicationTests(NeoTestBase):
         app.pt = Mock({ 'getCellListForTID': (cell, cell, ) })
         app.cp = Mock({ 'getConnForCell': ReturnValues(None, conn), })
         app.dispatcher = Mock()
-        app.tpc_begin(txn, tid)
         self.assertRaises(NEOStorageError, app.tpc_vote, txn,
             resolving_tryToResolveConflict)
         self.checkAskPacket(conn, Packets.AskStoreTransaction)
@@ -559,7 +559,6 @@ class ClientApplicationTests(NeoTestBase):
         app.pt = Mock({ 'getCellListForTID': (cell, cell, ) })
         app.cp = Mock({ 'getConnForCell': ReturnValues(None, conn), })
         app.dispatcher = Mock()
-        app.tpc_begin(txn, tid)
         app.tpc_vote(txn, resolving_tryToResolveConflict)
         self.checkAskStoreTransaction(conn)
         self.checkDispatcherRegisterCalled(app, conn)
@@ -656,8 +655,6 @@ class ClientApplicationTests(NeoTestBase):
             def pending(self, queue):
                 return not queue.empty()
         app.dispatcher = Dispatcher()
-        # begin a transaction
-        app.tpc_begin(txn, tid)
         # conflict occurs on storage 2
         app.store(oid1, tid, 'DATA', None, txn)
         app.store(oid2, tid, 'DATA', None, txn)
-- 
2.30.9