From 39e4f20e41acad9fcd25cf850a42bbcdd47b7cd2 Mon Sep 17 00:00:00 2001 From: wesleybl Date: Wed, 22 Sep 2021 00:45:55 -0300 Subject: [PATCH] Fix random failures on test_services_types plone.dexterity 2.10+ now uses the _p_mtime variable in the schema names. As this variable is related to date/time and the tests are executed very fast, some schema had the same name, when they shouldn't be. This was causing problems in the tests. So we introduce sleeps in Plone 5.2 with Python 2, so that the schemas don't have the same names. In Python 3 we don't have this problem because the precision of _p_mtime is higher in Python 3. --- .../restapi/tests/test_services_types.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/plone/restapi/tests/test_services_types.py b/src/plone/restapi/tests/test_services_types.py index 040204f996..2177d6db50 100644 --- a/src/plone/restapi/tests/test_services_types.py +++ b/src/plone/restapi/tests/test_services_types.py @@ -5,16 +5,33 @@ from plone.app.testing import SITE_OWNER_PASSWORD from plone.app.testing import TEST_USER_ID from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING +from plone.restapi.testing import PLONE_VERSION from plone.restapi.testing import RelativeSession +import six +import time import transaction import unittest +PYTHON2_PLONE52 = PLONE_VERSION.base_version >= "5.2" and six.PY2 + + class TestServicesTypes(unittest.TestCase): layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING + def sleep_python2_plone52(self, seconds=0.2): + """plone.dexterity 2.10+ now uses the _p_mtime variable in the schema names. + As this variable is related to date/time and the tests are executed very fast, + some schema had the same name, when they shouldn't be. This was causing + problems in the tests. So we introduce sleeps in Plone 5.2 with Python 2, + so that the schemas don't have the same names. In Python 3 we don't have this + problem because the precision of _p_mtime is higher in Python 3. + """ + if PYTHON2_PLONE52: + time.sleep(seconds) + def setUp(self): self.app = self.layer["app"] self.portal = self.layer["portal"] @@ -60,6 +77,7 @@ def setUp(self): "description": "Website of the author", }, ) + self.sleep_python2_plone52() def tearDown(self): # Remove all custom changed on Document @@ -114,6 +132,7 @@ def test_get_types_document_edit(self): ) # noqa def test_types_document_get_fieldset(self): + self.sleep_python2_plone52() response = self.api_session.get("/@types/Document/contact_info") self.assertEqual(response.status_code, 200) @@ -253,6 +272,7 @@ def test_types_document_patch_one_field(self): "required": False, }, ) + self.sleep_python2_plone52() self.assertEqual(response.status_code, 204) response = self.api_session.get("/@types/Document/author_email") @@ -317,6 +337,7 @@ def test_types_document_patch_create_missing(self): }, }, ) + self.sleep_python2_plone52(0.4) self.assertEqual(response.status_code, 204) response = self.api_session.get("/@types/Document") @@ -389,6 +410,7 @@ def test_types_document_put(self): } response = self.api_session.put("/@types/Document", json=doc_json) + self.sleep_python2_plone52(0.4) self.assertEqual(response.status_code, 204) response = self.api_session.get("/@types/Document") @@ -429,6 +451,7 @@ def test_types_document_remove_field(self): response = self.api_session.delete( "/@types/Document/author_email", ) + self.sleep_python2_plone52(0.4) self.assertEqual(response.status_code, 204) response = self.api_session.get("/@types/Document")