From 6ee97db88eec6ec3baa0c0a9f9d05ea7ae08b305 Mon Sep 17 00:00:00 2001 From: Asko Soukka Date: Sat, 7 May 2022 19:34:31 +0300 Subject: [PATCH 1/4] Try to ensure that WSGI server has stopped before returning from TestScopeWSGIServer testTearDown --- src/plone/app/robotframework/testing.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plone/app/robotframework/testing.py b/src/plone/app/robotframework/testing.py index 8e1a7d9..aef7bcc 100644 --- a/src/plone/app/robotframework/testing.py +++ b/src/plone/app/robotframework/testing.py @@ -156,6 +156,12 @@ def tearDown(self): def testTearDown(self): super(TestScopeWSGIServer, self).tearDown() + # Try to wait until server no longer responds. + if hasattr(self, "server"): + for i in range(10): + # There is implicit 0.3 second sleep per try. + if not self.server.wait(0): + return TEST_SCOPE_WSGI_SERVER_FIXTURE = TestScopeWSGIServer() From 4426060206264a0628b5340aaa8c8a784f27301b Mon Sep 17 00:00:00 2001 From: Asko Soukka Date: Sat, 7 May 2022 19:39:48 +0300 Subject: [PATCH 2/4] Try giving test scope WSGI SERVER fixture PLONE_FIXTURE as base to ensure it is called after PLONE_FIXTURE --- src/plone/app/robotframework/testing.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/plone/app/robotframework/testing.py b/src/plone/app/robotframework/testing.py index aef7bcc..8d8a6dd 100644 --- a/src/plone/app/robotframework/testing.py +++ b/src/plone/app/robotframework/testing.py @@ -137,7 +137,7 @@ def tearDown(self): # /> # -class TestScopeWSGIServer(WSGIServer): +class WSGIServerTestScope(WSGIServer): # Layer where WSGI server is shutdown on testTearDown to prevent requests # being processed between tests (which could lead to unexpected database @@ -147,15 +147,17 @@ class TestScopeWSGIServer(WSGIServer): # for convenience and similar "RobotServer" experience to the default # layer. + bases = (PLONE_FIXTURE,) + def testSetUp(self): if hasattr(self, "server") and self.server.was_shutdown: - super(TestScopeWSGIServer, self).setUp() + super(WSGIServerTestScope, self).setUp() def tearDown(self): pass def testTearDown(self): - super(TestScopeWSGIServer, self).tearDown() + super(WSGIServerTestScope, self).tearDown() # Try to wait until server no longer responds. if hasattr(self, "server"): for i in range(10): @@ -164,7 +166,7 @@ def testTearDown(self): return -TEST_SCOPE_WSGI_SERVER_FIXTURE = TestScopeWSGIServer() +WSGI_SERVER_TEST_SCOPE_FIXTURE = WSGIServerTestScope() RobotRemote = type( @@ -316,7 +318,7 @@ def __nonzero__(x): bases=( PLONE_ROBOT_FIXTURE, REMOTE_LIBRARY_BUNDLE_FIXTURE, - TEST_SCOPE_WSGI_SERVER_FIXTURE, + WSGI_SERVER_TEST_SCOPE_FIXTURE, ), name="Plone:Robot", ) From 51dc3e713de86de9c728de8a48eb15898d8efd89 Mon Sep 17 00:00:00 2001 From: Asko Soukka Date: Sat, 7 May 2022 20:08:19 +0300 Subject: [PATCH 3/4] Move WSgiServerTestScope fixture to better position --- src/plone/app/robotframework/testing.py | 63 +++++++++++++------------ 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/plone/app/robotframework/testing.py b/src/plone/app/robotframework/testing.py index 8d8a6dd..9f5d7b9 100644 --- a/src/plone/app/robotframework/testing.py +++ b/src/plone/app/robotframework/testing.py @@ -137,37 +137,6 @@ def tearDown(self): # /> # -class WSGIServerTestScope(WSGIServer): - - # Layer where WSGI server is shutdown on testTearDown to prevent requests - # being processed between tests (which could lead to unexpected database - # state). - - # Still starts with WSGI server being started at first on suite setUp - # for convenience and similar "RobotServer" experience to the default - # layer. - - bases = (PLONE_FIXTURE,) - - def testSetUp(self): - if hasattr(self, "server") and self.server.was_shutdown: - super(WSGIServerTestScope, self).setUp() - - def tearDown(self): - pass - - def testTearDown(self): - super(WSGIServerTestScope, self).tearDown() - # Try to wait until server no longer responds. - if hasattr(self, "server"): - for i in range(10): - # There is implicit 0.3 second sleep per try. - if not self.server.wait(0): - return - - -WSGI_SERVER_TEST_SCOPE_FIXTURE = WSGIServerTestScope() - RobotRemote = type( "RobotRemote", @@ -314,6 +283,38 @@ def __nonzero__(x): name="PloneRobot:Integration", ) + +class WSGIServerTestScope(WSGIServer): + + # Layer where WSGI server is shutdown on testTearDown to prevent requests + # being processed between tests (which could lead to unexpected database + # state). + + # Still starts with WSGI server being started at first on suite setUp + # for convenience and similar "RobotServer" experience to the default + # layer. + + bases = (PLONE_FIXTURE,) + + def testSetUp(self): + if hasattr(self, "server") and self.server.was_shutdown: + super(WSGIServerTestScope, self).setUp() + + def tearDown(self): + pass + + def testTearDown(self): + super(WSGIServerTestScope, self).tearDown() + # Try to wait until server no longer responds. + if hasattr(self, "server"): + for i in range(10): + # There is implicit 0.3 second sleep per try. + if not self.server.wait(0): + return + + +WSGI_SERVER_TEST_SCOPE_FIXTURE = WSGIServerTestScope() + PLONE_ROBOT_TESTING = FunctionalTesting( bases=( PLONE_ROBOT_FIXTURE, From 6ac8cddd635f8a7e7a5f5324f8990506a5fdb12f Mon Sep 17 00:00:00 2001 From: Asko Soukka Date: Sat, 7 May 2022 20:11:03 +0300 Subject: [PATCH 4/4] Add temporary debug prints --- src/plone/app/robotframework/server.py | 1 + src/plone/app/robotframework/testing.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plone/app/robotframework/server.py b/src/plone/app/robotframework/server.py index 0015186..4076ff9 100644 --- a/src/plone/app/robotframework/server.py +++ b/src/plone/app/robotframework/server.py @@ -316,6 +316,7 @@ def zodb_setup(self, layer_dotted_name=None): from zope.testrunner.runner import order_by_bases layers = order_by_bases([self.zope_layer]) + print(WAIT(layers)) for layer in layers: if hasattr(layer, "testSetUp"): if HAS_VERBOSE_CONSOLE: diff --git a/src/plone/app/robotframework/testing.py b/src/plone/app/robotframework/testing.py index 9f5d7b9..2a4e9bc 100644 --- a/src/plone/app/robotframework/testing.py +++ b/src/plone/app/robotframework/testing.py @@ -10,6 +10,7 @@ from plone.app.robotframework.remote import RemoteLibraryLayer from plone.app.robotframework.server import Zope2ServerRemote from plone.app.robotframework.users import Users +from plone.app.robotframework.server import WAIT from plone.app.testing import applyProfile from plone.app.testing import FunctionalTesting from plone.app.testing import IntegrationTesting @@ -137,7 +138,6 @@ def tearDown(self): # /> # - RobotRemote = type( "RobotRemote", ( @@ -296,14 +296,21 @@ class WSGIServerTestScope(WSGIServer): bases = (PLONE_FIXTURE,) + def setUp(self): + print(WAIT("WSGIServerTestScope:setUp")) + super(WSGIServerTestScope, self).setUp() + def testSetUp(self): + print(WAIT("WSGIServerTestScope:testSetUp")) if hasattr(self, "server") and self.server.was_shutdown: super(WSGIServerTestScope, self).setUp() def tearDown(self): + print(WAIT("WSGIServerTestScope:tearDown")) pass def testTearDown(self): + print(WAIT("WSGIServerTestScope:testTearDown")) super(WSGIServerTestScope, self).tearDown() # Try to wait until server no longer responds. if hasattr(self, "server"):