Commit 47b8ebdc authored by Chris McDonough's avatar Chris McDonough

Stresstest now calls values on TOC.

parent 8ac97850
...@@ -18,36 +18,47 @@ from Testing import makerequest ...@@ -18,36 +18,47 @@ from Testing import makerequest
import ZODB # in order to get Persistence.Persistent working import ZODB # in order to get Persistence.Persistent working
import Acquisition import Acquisition
from Acquisition import aq_base from Acquisition import aq_base
from Products.Sessions.BrowserIdManager import BrowserIdManager, getNewBrowserId from Products.Sessions.BrowserIdManager import BrowserIdManager, \
getNewBrowserId
from Products.Sessions.SessionDataManager import \ from Products.Sessions.SessionDataManager import \
SessionDataManager, SessionDataManagerErr SessionDataManager, SessionDataManagerErr
from Products.Transience.Transience import \ from Products.Transience.Transience import \
TransientObjectContainer, TransientObject TransientObjectContainer, TransientObject
from Products.TemporaryFolder.TemporaryFolder import MountedTemporaryFolder from Products.TemporaryFolder.TemporaryFolder import MountedTemporaryFolder
from Products.TemporaryFolder.LowConflictConnection import LowConflictConnection from Products.TemporaryFolder.LowConflictConnection import \
LowConflictConnection
from ZODB.Connection import Connection from ZODB.Connection import Connection
from ZODB.POSException import InvalidObjectReference, ConflictError, ReadConflictError, BTreesConflictError from ZODB.POSException import InvalidObjectReference, ConflictError, \
ReadConflictError, BTreesConflictError
from DateTime import DateTime from DateTime import DateTime
from unittest import TestCase, TestSuite, TextTestRunner, makeSuite from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
import time, threading, random import time, threading, random
from cPickle import UnpickleableError from cPickle import UnpickleableError
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
from Products.TemporaryFolder.TemporaryStorage import TemporaryStorage
from OFS.Application import Application from OFS.Application import Application
import sys import sys
from zLOG import log_time from zLOG import log_time
sys.setcheckinterval(200) sys.setcheckinterval(200)
import fauxtime
import Products.Transience.Transience
import Products.Transience.TransientObject
Products.Transience.Transience.time = fauxtime
Products.Transience.TransientObject.time = fauxtime
tf_name = 'temp_folder' tf_name = 'temp_folder'
idmgr_name = 'browser_id_manager' idmgr_name = 'browser_id_manager'
toc_name = 'temp_transient_container' toc_name = 'temp_transient_container'
sdm_name = 'session_data_manager'
stuff = {} stuff = {}
def _getDB(): def _getDB():
db = stuff.get('db') db = stuff.get('db')
if not db: if not db:
ds = DemoStorage(quota=(1<<20)) ds = DemoStorage()
db = ZODB.DB(ds, pool_size=60) db = ZODB.DB(ds)
conn = db.open() conn = db.open()
root = conn.root() root = conn.root()
app = Application() app = Application()
...@@ -69,7 +80,7 @@ def _populate(app): ...@@ -69,7 +80,7 @@ def _populate(app):
tf = MountedTemporaryFolder(tf_name, title="Temporary Folder") tf = MountedTemporaryFolder(tf_name, title="Temporary Folder")
toc = TransientObjectContainer(toc_name, title='Temporary ' toc = TransientObjectContainer(toc_name, title='Temporary '
'Transient Object Container', timeout_mins=1) 'Transient Object Container', timeout_mins=1)
session_data_manager=SessionDataManager(id='session_data_manager', session_data_manager=SessionDataManager(id=sdm_name,
path='/'+tf_name+'/'+toc_name, title='Session Data Manager') path='/'+tf_name+'/'+toc_name, title='Session Data Manager')
try: app._delObject(idmgr_name) try: app._delObject(idmgr_name)
...@@ -78,12 +89,12 @@ def _populate(app): ...@@ -78,12 +89,12 @@ def _populate(app):
try: app._delObject(tf_name) try: app._delObject(tf_name)
except AttributeError: pass except AttributeError: pass
try: app._delObject('session_data_manager') try: app._delObject(sdm_name)
except AttributeError: pass except AttributeError: pass
app._setObject(idmgr_name, bidmgr) app._setObject(idmgr_name, bidmgr)
app._setObject('session_data_manager', session_data_manager) app._setObject(sdm_name, session_data_manager)
app._setObject(tf_name, tf) app._setObject(tf_name, tf)
get_transaction().commit() get_transaction().commit()
...@@ -93,47 +104,32 @@ def _populate(app): ...@@ -93,47 +104,32 @@ def _populate(app):
class TestMultiThread(TestCase): class TestMultiThread(TestCase):
def testOverlappingBrowserIds(self): def testOverlappingBrowserIds(self):
readers = [] token = getNewBrowserId()
writers = [] self.go(token)
readiters = 20
writeiters = 5
readout = []
writeout = []
numreaders = 20
numwriters = 5
sdm_name = 'session_data_manager'
db = _getDB()
for i in range(numreaders):
thread = ReaderThread(db, readiters, sdm_name)
readers.append(thread)
for i in range(numwriters):
thread = WriterThread(db, writeiters, sdm_name)
writers.append(thread)
for thread in readers:
thread.start()
time.sleep(0.1)
for thread in writers:
thread.start()
time.sleep(0.1)
while threading.activeCount() > 1:
time.sleep(1)
def testNonOverlappingBrowserIds(self): def testNonOverlappingBrowserIds(self):
token = None
self.go(token)
def go(self, token):
readers = [] readers = []
writers = [] writers = []
readiters = 20 readiters = 100
writeiters = 5 writeiters = 100
readout = [] readout = []
writeout = [] writeout = []
numreaders = 20 numreaders = 4
numwriters = 5 numwriters = 2
sdm_name = 'session_data_manager' numvaluers = 1
db = _getDB() db = _getDB()
for i in range(numreaders): for i in range(numreaders):
thread = ReaderThread(db, readiters, sdm_name) thread = ReaderThread(db, readiters, token)
readers.append(thread)
for i in range(numvaluers):
thread = ValuesGetterThread(db, readiters, token)
readers.append(thread) readers.append(thread)
for i in range(numwriters): for i in range(numwriters):
thread = WriterThread(db, writeiters, sdm_name) thread = WriterThread(db, writeiters, token)
writers.append(thread) writers.append(thread)
for thread in readers: for thread in readers:
thread.start() thread.start()
...@@ -141,15 +137,19 @@ class TestMultiThread(TestCase): ...@@ -141,15 +137,19 @@ class TestMultiThread(TestCase):
for thread in writers: for thread in writers:
thread.start() thread.start()
time.sleep(0.1) time.sleep(0.1)
while threading.activeCount() > 1: active = 2
while active > 1:
active = threading.activeCount()
print 'waiting for %s threads' % active
time.sleep(1) time.sleep(1)
class BaseReaderWriter(threading.Thread): class BaseReaderWriter(threading.Thread):
def __init__(self, db, iters, sdm_name): def __init__(self, db, iters, token=None):
self.conn = db.open() self.conn = db.open()
self.app = self.conn.root()['Application'] self.app = self.conn.root()['Application']
self.app = makerequest.makerequest(self.app) self.app = makerequest.makerequest(self.app)
token = getNewBrowserId() if token is None:
token = getNewBrowserId()
self.app.REQUEST.browser_id_ = token self.app.REQUEST.browser_id_ = token
self.iters = iters self.iters = iters
self.sdm_name = sdm_name self.sdm_name = sdm_name
...@@ -208,6 +208,20 @@ class WriterThread(BaseReaderWriter): ...@@ -208,6 +208,20 @@ class WriterThread(BaseReaderWriter):
else: else:
get_transaction().abort() get_transaction().abort()
class ValuesGetterThread(BaseReaderWriter):
def run1(self):
tf = getattr(self.app, tf_name)
toc = getattr(tf, toc_name)
for i in range(self.iters):
print '%s values in toc' % len(toc.values())
n = random.choice(range(3))
time.sleep(n)
if n % 2 == 0:
get_transaction().commit()
else:
get_transaction().abort()
def test_suite(): def test_suite():
test_multithread = makeSuite(TestMultiThread, 'test') test_multithread = makeSuite(TestMultiThread, 'test')
suite = TestSuite((test_multithread,)) suite = TestSuite((test_multithread,))
......
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