Commit e605544e authored by Jérome Perrin's avatar Jérome Perrin

ERP5TypeLiveTestCase: close request at the end of each test

This is supposed to fix "Should not load state for ${oid of a skin} when
the connection is closed" sometimes happening with live tests (especially
when the test self.publish and the developer access the site while the
test is suspended on a debugger breakpoint).

The object accessed after the connection is closed was a skin (python
script, sometimes page template or form) that was cached in SKINDATA.
The mechanism to prune entries from the cache uses REQUEST.hold API
which expects that REQUEST.close is called on request, but because
requests were not closed at the end of the request, it happened that
the cache was reused from another connection.

This change to close the requests, like ERP5TypeTestCase is doing in
tearDown (the actual close is done by Testing.ZopeTestCase.connections).

By closing requests at the end of tests, we also have to change so that
at the beginning of the test we initialize the request, by using the same
setSite and setupCurrentSkin that are done in ERP5TypeTestCase.
parent 8a8f9384
Pipeline #23009 passed with stage
......@@ -32,6 +32,8 @@ import sys
import imp
import re
from zope.site.hooks import setSite
from Acquisition import aq_base
from Testing import ZopeTestCase
from Testing.ZopeTestCase import PortalTestCase, user_name
from Products.CMFCore.utils import getToolByName
......@@ -88,7 +90,9 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
# reconstruct the acquisition chain with an independent request.
# RequestContainer -> Application -> Site
from Testing.ZopeTestCase.utils import makerequest
portal = getattr(makerequest(site.aq_parent), site.getId())
portal = getattr(
makerequest(aq_base(site.aq_parent)),
site.getId())
# Make the various get_request patches return this request.
# This is for ERP5TypeTestCase patch
......@@ -106,6 +110,8 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
request['SERVER_URL'] = _request_server_url
request._resetURLS()
portal.setupCurrentSkin(request)
setSite(portal)
self.portal = portal
return portal
......@@ -129,6 +135,8 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
if getattr(self, "activity_tool_subscribed", False):
self.portal.portal_activities.subscribe()
self.commit()
if self.portal is not None:
self.portal.REQUEST.close()
def _setup(self):
'''Change some site properties in order to be ready for live test
......
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