Commit 84fe7245 authored by Jim Fulton's avatar Jim Fulton

Fixed a test bug that caused checkCurrentSerialInTransaction to be

tested incorrectly for ZEO.
parent 4f4e2bd0
......@@ -249,6 +249,30 @@ class GenericTests(
key = '%s:%s' % (self._storage._storage, self._storage._server_addr)
self.assertEqual(self._storage.sortKey(), key)
def _do_store_in_separate_thread(self, oid, revid):
def do_store():
store = ZEO.ClientStorage.ClientStorage(self._storage._addr)
try:
t = transaction.get()
store.tpc_begin(t)
store.store(oid, revid, 'x', '', t)
store.tpc_vote(t)
store.tpc_finish(t)
except Exception, v:
import traceback
print 'E'*70
print v
traceback.print_exception(*sys.exc_info())
finally:
store.close()
thread = threading.Thread(name='T2', target=do_store)
thread.setDaemon(True)
thread.start()
thread.join(.2)
return thread
class FullGenericTests(
GenericTests,
Cache.TransUndoStorageWithCache,
......
......@@ -24,6 +24,8 @@ from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle
from ZODB.tests.StorageTestBase import handle_serials
import threading
import time
import transaction
import zope.interface
import zope.interface.verify
......@@ -200,12 +202,21 @@ class BasicStorage:
self._storage.tpc_finish(t)
t.commit()
def _do_store_in_separate_thread(self, oid, revid):
# We'll run the competing trans in a separate thread:
thread = threading.Thread(name='T2',
target=self._dostore, args=(oid,), kwargs=dict(revid=revid))
thread.setDaemon(True)
thread.start()
thread.join(.2)
return thread
def check_checkCurrentSerialInTransaction(self):
oid = '\0\0\0\0\0\0\0\xf0'
tid = self._dostore(oid)
tid2 = self._dostore(oid, revid=tid)
#----------------------------------------------------------------------
# stale read
transaction.begin()
t = transaction.get()
......@@ -219,11 +230,12 @@ class BasicStorage:
self.assert_(v.oid) == oid
self.assert_(v.serials == (tid2, tid))
else:
self.assert_(False, "No conflict error")
if 0: self.assert_(False, "No conflict error")
self._storage.tpc_abort(t)
#----------------------------------------------------------------------
# non-stale read, no stress. :)
transaction.begin()
t = transaction.get()
......@@ -234,8 +246,9 @@ class BasicStorage:
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
#----------------------------------------------------------------------
# non-stale read, competition after vote. The competing
# transaction most produce a tid > this transaction's tid
# transaction must produce a tid > this transaction's tid
transaction.begin()
t = transaction.get()
self._storage.tpc_begin(t)
......@@ -245,17 +258,14 @@ class BasicStorage:
self._storage.tpc_vote(t)
# We'll run the competing trans in a separate thread:
import threading, time
thread = threading.Thread(name='T1',
target=self._dostore, args=(oid,), kwargs=dict(revid=tid2))
thread.start()
time.sleep(.1)
thread = self._do_store_in_separate_thread(oid, tid2)
self._storage.tpc_finish(t)
thread.join()
thread.join(1)
tid3 = self._storage.load(oid)[1]
self.assert_(tid3 > self._storage.load('\0\0\0\0\0\0\0\xf3')[1])
#----------------------------------------------------------------------
# non-stale competing trans after checkCurrentSerialInTransaction
transaction.begin()
t = transaction.get()
......@@ -264,11 +274,7 @@ class BasicStorage:
'\0\0\0\0\0\0\0\0', 'x', '', t)
self._storage.checkCurrentSerialInTransaction(oid, tid3, t)
# We'll run the competing trans in a separate thread:
thread = threading.Thread(name='T2',
target=self._dostore, args=(oid,), kwargs=dict(revid=tid3))
thread.start()
time.sleep(.1)
thread = self._do_store_in_separate_thread(oid, tid3)
# There are 2 possibilities:
# 1. The store happens before this transaction completes,
......@@ -277,7 +283,7 @@ class BasicStorage:
# tid of the object is greater than this transaction's tid.
try:
self._storage.tpc_vote(t)
except ReadConflictError:
except POSException.ReadConflictError:
thread.join() # OK :)
else:
self._storage.tpc_finish(t)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment