Blame view

ZODB3.patch 8.85 KB
Julien Muchembled committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
Patch to ZODB3 for ZODB unit tests.
See also monkey-patch to Connection.tpc_finish in neo/client/__init__.py

Index: src/ZODB/tests/BasicStorage.py
===================================================================
--- src/ZODB/tests/BasicStorage.py	(revision 122777)
+++ src/ZODB/tests/BasicStorage.py	(working copy)
@@ -72,8 +72,10 @@
         r1 = self._storage.store(oid, None, zodb_pickle(MinPO(11)),
                                        '', txn)
         r2 = self._storage.tpc_vote(txn)
-        self._storage.tpc_finish(txn)
+        serial = self._storage.tpc_finish(txn)
         newrevid = handle_serials(oid, r1, r2)
+        if newrevid is None and serial is not None:
+            newrevid = serial
         data, revid = self._storage.load(oid, '')
         value = zodb_unpickle(data)
         eq(value, MinPO(11))
Index: src/ZODB/tests/TransactionalUndoStorage.py
===================================================================
--- src/ZODB/tests/TransactionalUndoStorage.py	(revision 122777)
+++ src/ZODB/tests/TransactionalUndoStorage.py	(working copy)
@@ -76,6 +76,12 @@
     def _transaction_newserial(self, oid):
         return self.__serials[oid]
 
+    def _transaction_finish(self, t, oid_list):
+        tid = self._storage.tpc_finish(t)
+        if tid is not None:
+            for oid in oid_list:
+                self.__serials[oid] = tid
+
     def _multi_obj_transaction(self, objs):
         newrevs = {}
         t = Transaction()
@@ -85,7 +91,7 @@
             self._transaction_store(oid, rev, data, '', t)
             newrevs[oid] = None
         self._transaction_vote(t)
-        self._storage.tpc_finish(t)
+        self._transaction_finish(t, [x[0] for x in objs])
         for oid in newrevs.keys():
             newrevs[oid] = self._transaction_newserial(oid)
         return newrevs
@@ -218,9 +224,9 @@
         self._transaction_store(oid2, revid2, p51, '', t)
         # Finish the transaction
         self._transaction_vote(t)
+        self._transaction_finish(t, [oid1, oid2])
         revid1 = self._transaction_newserial(oid1)
         revid2 = self._transaction_newserial(oid2)
-        self._storage.tpc_finish(t)
         eq(revid1, revid2)
         # Update those same two objects
         t = Transaction()
@@ -230,9 +236,9 @@
         self._transaction_store(oid2, revid2, p52, '', t)
         # Finish the transaction
         self._transaction_vote(t)
+        self._transaction_finish(t, [oid1, oid2])
         revid1 = self._transaction_newserial(oid1)
         revid2 = self._transaction_newserial(oid2)
-        self._storage.tpc_finish(t)
         eq(revid1, revid2)
         # Make sure the objects have the current value
         data, revid1 = self._storage.load(oid1, '')
@@ -288,11 +294,12 @@
         tid1 = info[1]['id']
         t = Transaction()
         oids = self._begin_undos_vote(t, tid, tid1)
-        self._storage.tpc_finish(t)
+        serial = self._storage.tpc_finish(t)
         # We get the finalization stuff called an extra time:
-        eq(len(oids), 4)
-        unless(oid1 in oids)
-        unless(oid2 in oids)
+        if serial is None:
+            eq(len(oids), 4)
+            unless(oid1 in oids)
+            unless(oid2 in oids)
         data, revid1 = self._storage.load(oid1, '')
         eq(zodb_unpickle(data), MinPO(30))
         data, revid2 = self._storage.load(oid2, '')
@@ -326,7 +333,7 @@
         self._transaction_store(oid2, revid2, p52, '', t)
         # Finish the transaction
         self._transaction_vote(t)
-        self._storage.tpc_finish(t)
+        self._transaction_finish(t, [oid1, oid2])
         revid1 = self._transaction_newserial(oid1)
         revid2 = self._transaction_newserial(oid2)
         eq(revid1, revid2)
@@ -346,7 +353,7 @@
         self._transaction_store(oid2, revid2, p53, '', t)
         # Finish the transaction
         self._transaction_vote(t)
-        self._storage.tpc_finish(t)
+        self._transaction_finish(t, [oid1, oid2])
         revid1 = self._transaction_newserial(oid1)
         revid2 = self._transaction_newserial(oid2)
         eq(revid1, revid2)
@@ -358,10 +365,11 @@
         tid = info[1]['id']
         t = Transaction()
         oids = self._begin_undos_vote(t, tid)
-        self._storage.tpc_finish(t)
-        eq(len(oids), 1)
-        self.failUnless(oid1 in oids)
-        self.failUnless(not oid2 in oids)
+        serial = self._storage.tpc_finish(t)
+        if serial is None:
+            eq(len(oids), 1)
+            self.failUnless(oid1 in oids)
+            self.failUnless(not oid2 in oids)
         data, revid1 = self._storage.load(oid1, '')
         eq(zodb_unpickle(data), MinPO(33))
         data, revid2 = self._storage.load(oid2, '')
@@ -397,7 +405,7 @@
         self._transaction_store(oid1, revid1, p81, '', t)
         self._transaction_store(oid2, revid2, p91, '', t)
         self._transaction_vote(t)
-        self._storage.tpc_finish(t)
+        self._transaction_finish(t, [oid1, oid2])
         revid1 = self._transaction_newserial(oid1)
         revid2 = self._transaction_newserial(oid2)
         eq(revid1, revid2)
Index: src/ZODB/tests/StorageTestBase.py
===================================================================
--- src/ZODB/tests/StorageTestBase.py	(revision 122777)
+++ src/ZODB/tests/StorageTestBase.py	(working copy)
@@ -134,7 +134,7 @@
 
     A helper for function _handle_all_serials().
     """
-    return handle_all_serials(oid, *args)[oid]
+    return handle_all_serials(oid, *args).get(oid)
 
 def import_helper(name):
     __import__(name)
@@ -191,7 +191,9 @@
             # Finish the transaction
             r2 = self._storage.tpc_vote(t)
             revid = handle_serials(oid, r1, r2)
-            self._storage.tpc_finish(t)
+            serial = self._storage.tpc_finish(t)
+            if serial is not None and revid is None:
+                revid = serial
         except:
             self._storage.tpc_abort(t)
             raise
@@ -211,8 +213,8 @@
         self._storage.tpc_begin(t)
         undo_result = self._storage.undo(tid, t)
         vote_result = self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        if expected_oids is not None:
+        serial = self._storage.tpc_finish(t)
+        if expected_oids is not None and serial is None:
             oids = undo_result and undo_result[1] or []
             oids.extend(oid for (oid, _) in vote_result or ())
             self.assertEqual(len(oids), len(expected_oids), repr(oids))
Index: src/ZODB/tests/MTStorage.py
===================================================================
--- src/ZODB/tests/MTStorage.py	(revision 122777)
+++ src/ZODB/tests/MTStorage.py	(working copy)
@@ -155,10 +155,12 @@
         r2 = self.storage.tpc_vote(t)
         self.pause()
 
-        self.storage.tpc_finish(t)
+        serial = self.storage.tpc_finish(t)
         self.pause()
 
         revid = handle_serials(oid, r1, r2)
+        if serial is not None and revid is None:
+            revid = serial
         self.oids[oid] = revid
 
 class ExtStorageClientThread(StorageClientThread):
Index: src/ZODB/tests/RevisionStorage.py
===================================================================
--- src/ZODB/tests/RevisionStorage.py	(revision 122777)
+++ src/ZODB/tests/RevisionStorage.py	(working copy)
@@ -150,10 +150,12 @@
                 # Finish the transaction
                 r2 = self._storage.tpc_vote(t)
                 newrevid = handle_serials(oid, r1, r2)
-                self._storage.tpc_finish(t)
+                serial = self._storage.tpc_finish(t)
             except:
                 self._storage.tpc_abort(t)
                 raise
+            if serial is not None and newrevid is None:
+                newrevid = serial
             return newrevid
         revid1 = helper(1, None, 1)
         revid2 = helper(2, revid1, 2)
Index: src/ZODB/interfaces.py
===================================================================
--- src/ZODB/interfaces.py	(revision 122777)
+++ src/ZODB/interfaces.py	(working copy)
@@ -776,6 +776,10 @@
         called while the storage transaction lock is held.  It takes
         the new transaction id generated by the transaction.
 
+        The return value can be either None or a serial giving new
+        serial for objects whose ids were passed to previous store calls
+        in the same transaction, and for which no serial was returned
+        from either store or tpc_vote for objects passed to store.
         """
 
     def tpc_vote(transaction):
@@ -794,8 +798,6 @@
         The return value can be either None or a sequence of object-id
         and serial pairs giving new serials for objects who's ids were
         passed to previous store calls in the same transaction.
-        After the tpc_vote call, new serials must have been returned,
-        either from tpc_vote or store for objects passed to store.
 
         A serial returned in a sequence of oid/serial pairs, may be
         the special value ZODB.ConflictResolution.ResolvedSerial to