Commit 35c20cf9 authored by Vincent Pelletier's avatar Vincent Pelletier

testERP5Catalog: TransactionThread reraises exceptions on join.

parent 8cf35515
...@@ -33,6 +33,7 @@ import threading ...@@ -33,6 +33,7 @@ import threading
import traceback import traceback
import unittest import unittest
import httplib import httplib
import six
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from DateTime import DateTime from DateTime import DateTime
...@@ -67,20 +68,39 @@ class TransactionThread(threading.Thread): ...@@ -67,20 +68,39 @@ class TransactionThread(threading.Thread):
self.root_physical_path = portal.getPhysicalPath() self.root_physical_path = portal.getPhysicalPath()
self.payload = payload self.payload = payload
self.payload_kw = payload_kw self.payload_kw = payload_kw
self.exception = None
def run(self): def run(self):
# Get a new portal, in a new transactional connection bound to default try:
# transaction manager (which should be the threaded transaction manager). # Get a new portal, in a new transactional connection bound to default
portal = self.zodb.open().root()['Application'].unrestrictedTraverse( # transaction manager (which should be the threaded transaction manager).
self.root_physical_path, portal = self.zodb.open().root()['Application'].unrestrictedTraverse(
) self.root_physical_path,
# Trigger ERP5Site magic )
portal.getSiteManager() # Trigger ERP5Site magic
# Trigger skin magic portal.getSiteManager()
portal.changeSkin(None) # Trigger skin magic
# Login portal.changeSkin(None)
newSecurityManager(None, portal.acl_users.getUser('ERP5TypeTestCase')) # Login
self.payload(portal=portal, **dict(self.payload_kw)) newSecurityManager(None, portal.acl_users.getUser('ERP5TypeTestCase'))
self.payload(portal=portal, **dict(self.payload_kw))
except Exception as self.exception:
if six.PY2:
self.exception.__traceback__ = sys.exc_info()[2]
def join(self, *args, **kw):
super(TransactionThread, self).join(*args, **kw)
if not self.is_alive():
exception = self.exception
# Break reference cycle:
# run frame -> self -> exception -> __traceback__ -> run frame
# Not re-raising on subsequent calls is kind of a bug, but it's really up
# to caller to either not ignore exceptions or keep them around.
self.exception = None
if exception is not None:
if six.PY3:
raise exception
six.reraise(exception, None, exception.__traceback__)
class IndexableDocument(ObjectManager): class IndexableDocument(ObjectManager):
......
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