Skip to content

Commit

Permalink
[fc] Repository: Products.Archetypes
Browse files Browse the repository at this point in the history
Branch: refs/heads/master
Date: 2019-04-09T10:42:41+02:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/Products.Archetypes@5acdaa5

Fixed slowness in unicodeTestIn script used by keyword template.

Fixes plone/Products.Archetypes#125

This contains performance tests, which are ignored by default, but can be activated by exporting a number:
$ export AT_UNICODETESTIN=3000
$ bin/test -s Products.Archetypes -m test_widgets -t test_unicodeTestIn
...
Testing unicodeTestIn with 3000 items, and 50 selected.
...

Timings before this fix:

First test part finished in 4.2931 seconds
Second test part finished in 12.6825 seconds

Timings after this fix:

First test part finished in 0.0373 seconds
Second test part finished in 0.2010 seconds

And with the fix and 30,000 items:

First test part finished in 0.0374 seconds
Second test part finished in 2.0301 seconds

Files changed:
A news/125.bugfix
M Products/Archetypes/skins/archetypes/unicodeTestIn.py
M Products/Archetypes/tests/test_widgets.py
Repository: Products.Archetypes

Branch: refs/heads/master
Date: 2019-04-10T11:10:07+02:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: plone/Products.Archetypes@aa05381

Merge pull request #128 from plone/maurits-issue-125-unicode-test-in-master

Fixed slowness in unicodeTestIn script used by keyword template. [master]

Files changed:
A news/125.bugfix
M Products/Archetypes/skins/archetypes/unicodeTestIn.py
M Products/Archetypes/tests/test_widgets.py
  • Loading branch information
jensens committed Apr 10, 2019
1 parent a379a41 commit a3ff903
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions last_commit.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,60 @@
Repository: Products.CMFPlone
Repository: Products.Archetypes


Branch: refs/heads/master
Date: 2019-04-09T14:15:49+02:00
Date: 2019-04-09T10:42:41+02:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: https://github.com/plone/Products.CMFPlone/commit/a43f0d9deead63c1e24c966bd0f1fa560f8058b0
Commit: https://github.com/plone/Products.Archetypes/commit/5acdaa56eaf4eb0d2b79b311890fcd36e7c9efad

Fixed unstable Markup Control Panel robot test again.
Fixed slowness in unicodeTestIn script used by keyword template.

The trick seems to be to first check the allowed type that we want to add,
and then uncheck the other ones.
Otherwise you get a slightly belated validation error before pressing Save,
and the Save has no effect.
Fixes https://github.com/plone/Products.Archetypes/issues/125

(If this does not help, we really have to add a 'Sleep 1' before pressing Save.)
This contains performance tests, which are ignored by default, but can be activated by exporting a number:
$ export AT_UNICODETESTIN=3000
$ bin/test -s Products.Archetypes -m test_widgets -t test_unicodeTestIn
...
Testing unicodeTestIn with 3000 items, and 50 selected.
...

Timings before this fix:

First test part finished in 4.2931 seconds
Second test part finished in 12.6825 seconds

Timings after this fix:

First test part finished in 0.0373 seconds
Second test part finished in 0.2010 seconds

And with the fix and 30,000 items:

First test part finished in 0.0374 seconds
Second test part finished in 2.0301 seconds

Files changed:
A news/2809.bugfix
M Products/CMFPlone/tests/robot/test_controlpanel_markup.robot
A news/125.bugfix
M Products/Archetypes/skins/archetypes/unicodeTestIn.py
M Products/Archetypes/tests/test_widgets.py

b'diff --git a/Products/CMFPlone/tests/robot/test_controlpanel_markup.robot b/Products/CMFPlone/tests/robot/test_controlpanel_markup.robot\nindex b455c5cf4..1df997158 100644\n--- a/Products/CMFPlone/tests/robot/test_controlpanel_markup.robot\n+++ b/Products/CMFPlone/tests/robot/test_controlpanel_markup.robot\n@@ -46,12 +46,11 @@ the markup control panel\n # --- WHEN -------------------------------------------------------------------\n \n I set allowed types to "${type}"\n- [Documentation] \'Wait until page contains Changes saved\' is nicer, but is unstable. See https://github.com/plone/Products.CMFPlone/issues/2809\n+ with the label ${type} Select Checkbox\n with the label text/html UnSelect Checkbox\n with the label text/x-web-textile UnSelect Checkbox\n- with the label ${type} Select Checkbox\n Click Button Save\n- Go to ${PLONE_URL}/@@markup-controlpanel\n+ Wait until page contains Changes saved\n Checkbox Should Be Selected ${type}\n Checkbox Should Not Be Selected text/html\n Checkbox Should Not Be Selected text/x-web-textile\ndiff --git a/news/2809.bugfix b/news/2809.bugfix\nnew file mode 100644\nindex 000000000..9e3c9b8e1\n--- /dev/null\n+++ b/news/2809.bugfix\n@@ -0,0 +1 @@\n+Fixed unstable Markup Control Panel robot test again. [maurits]\n'
b"diff --git a/Products/Archetypes/skins/archetypes/unicodeTestIn.py b/Products/Archetypes/skins/archetypes/unicodeTestIn.py\nindex 23b9914e..6879754e 100644\n--- a/Products/Archetypes/skins/archetypes/unicodeTestIn.py\n+++ b/Products/Archetypes/skins/archetypes/unicodeTestIn.py\n@@ -9,10 +9,11 @@\n \n if vocab is None or len(vocab) == 0:\n return 0\n-\n-value = context.unicodeEncode(value)\n+if not isinstance(value, str):\n+ value = value.encode('utf-8')\n for v in vocab:\n- if context.unicodeEncode(v) == value:\n+ if not isinstance(v, str):\n+ v = v.encode('utf-8')\n+ if v == value:\n return True\n-\n return False\ndiff --git a/Products/Archetypes/tests/test_widgets.py b/Products/Archetypes/tests/test_widgets.py\nindex 7058daec..de4448b5 100644\n--- a/Products/Archetypes/tests/test_widgets.py\n+++ b/Products/Archetypes/tests/test_widgets.py\n@@ -116,13 +116,38 @@ def test_unicodeTestIn(self):\n # The unicodeTestIn script can be called very often on edit\n # forms when you have lots of keywords (Subject) in your site.\n # So an interesting test here is: how fast is this? For a\n- # speed test, uncomment the next few lines. It basically\n- # tests having 3000 keywords, of which 50 are selected on a\n- # page. The related change in unicodeTestIn speeds this up\n+ # speed test, run the tests with 'export AT_UNICODETESTIN=3000'.\n+ # It basically tests having 3000 keywords, of which 50 are selected\n+ # on a page. The related change in unicodeTestIn speeds this up\n # from 42 to 15 seconds.\n- #vocab += [str(x) for x in range(3000)]\n- # for x in range(1000, 1050):\n- # self.assertEqual(self.portal.unicodeTestIn(str(x), vocab), True)\n+ # And 9 years later it is 4.4 seconds for only this first part.\n+ # And 0.03 seconds after some simple fixes to the script.\n+ number = int(os.getenv('AT_UNICODETESTIN', 0))\n+ if not number:\n+ return\n+ from time import time\n+ print('\\nTesting unicodeTestIn with {0} items, 50 selected.'.format(\n+ number))\n+ vocab += [str(x) for x in range(number)]\n+ value = [str(x) for x in range(1000, 1050)]\n+ time1 = time()\n+ for v in value:\n+ self.assertEqual(self.portal.unicodeTestIn(v, vocab), True)\n+ time2 = time()\n+ print('First test part finished in {0:.4f} seconds'.format(\n+ time2 - time1))\n+\n+ # This is actually more how it is used:\n+ # a large vocabulary, which is compared with a much smaller\n+ # list of selected items. Originally took 12.6 seconds for 3000 items.\n+ # And 0.2 seconds after some simple fixes.\n+ for v in vocab:\n+ # Some of these are True, others False, so we don't test the outcome.\n+ # We only call this to test the speed.\n+ self.portal.unicodeTestIn(v, value)\n+ time3 = time()\n+ print('Second test part finished in {0:.4f} seconds'.format(\n+ time3 - time2))\n \n def _test_widgets(self):\n doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')\ndiff --git a/news/125.bugfix b/news/125.bugfix\nnew file mode 100644\nindex 00000000..b992e988\n--- /dev/null\n+++ b/news/125.bugfix\n@@ -0,0 +1,2 @@\n+Fixed slowness in ``unicodeTestIn`` script used by keyword template.\n+[maurits]\n\\ No newline at end of file\n"

Repository: Products.CMFPlone
Repository: Products.Archetypes


Branch: refs/heads/master
Date: 2019-04-09T16:12:50+02:00
Date: 2019-04-10T11:10:07+02:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: https://github.com/plone/Products.CMFPlone/commit/183982b1dec33f56c4e6f5e5fe182efa6f780c91
Commit: https://github.com/plone/Products.Archetypes/commit/aa053811b649528798218a78680abd1fd2aefa42

Merge pull request #2826 from plone/maurits-issue-2809-unstable-robot-markup-2
Merge pull request #128 from plone/maurits-issue-125-unicode-test-in-master

Fixed unstable Markup Control Panel robot test again.
Fixed slowness in unicodeTestIn script used by keyword template. [master]

Files changed:
A news/2809.bugfix
M Products/CMFPlone/tests/robot/test_controlpanel_markup.robot
A news/125.bugfix
M Products/Archetypes/skins/archetypes/unicodeTestIn.py
M Products/Archetypes/tests/test_widgets.py

b'diff --git a/Products/CMFPlone/tests/robot/test_controlpanel_markup.robot b/Products/CMFPlone/tests/robot/test_controlpanel_markup.robot\nindex b455c5cf4..1df997158 100644\n--- a/Products/CMFPlone/tests/robot/test_controlpanel_markup.robot\n+++ b/Products/CMFPlone/tests/robot/test_controlpanel_markup.robot\n@@ -46,12 +46,11 @@ the markup control panel\n # --- WHEN -------------------------------------------------------------------\n \n I set allowed types to "${type}"\n- [Documentation] \'Wait until page contains Changes saved\' is nicer, but is unstable. See https://github.com/plone/Products.CMFPlone/issues/2809\n+ with the label ${type} Select Checkbox\n with the label text/html UnSelect Checkbox\n with the label text/x-web-textile UnSelect Checkbox\n- with the label ${type} Select Checkbox\n Click Button Save\n- Go to ${PLONE_URL}/@@markup-controlpanel\n+ Wait until page contains Changes saved\n Checkbox Should Be Selected ${type}\n Checkbox Should Not Be Selected text/html\n Checkbox Should Not Be Selected text/x-web-textile\ndiff --git a/news/2809.bugfix b/news/2809.bugfix\nnew file mode 100644\nindex 000000000..9e3c9b8e1\n--- /dev/null\n+++ b/news/2809.bugfix\n@@ -0,0 +1 @@\n+Fixed unstable Markup Control Panel robot test again. [maurits]\n'
b"diff --git a/Products/Archetypes/skins/archetypes/unicodeTestIn.py b/Products/Archetypes/skins/archetypes/unicodeTestIn.py\nindex 23b9914e..6879754e 100644\n--- a/Products/Archetypes/skins/archetypes/unicodeTestIn.py\n+++ b/Products/Archetypes/skins/archetypes/unicodeTestIn.py\n@@ -9,10 +9,11 @@\n \n if vocab is None or len(vocab) == 0:\n return 0\n-\n-value = context.unicodeEncode(value)\n+if not isinstance(value, str):\n+ value = value.encode('utf-8')\n for v in vocab:\n- if context.unicodeEncode(v) == value:\n+ if not isinstance(v, str):\n+ v = v.encode('utf-8')\n+ if v == value:\n return True\n-\n return False\ndiff --git a/Products/Archetypes/tests/test_widgets.py b/Products/Archetypes/tests/test_widgets.py\nindex 7058daec..de4448b5 100644\n--- a/Products/Archetypes/tests/test_widgets.py\n+++ b/Products/Archetypes/tests/test_widgets.py\n@@ -116,13 +116,38 @@ def test_unicodeTestIn(self):\n # The unicodeTestIn script can be called very often on edit\n # forms when you have lots of keywords (Subject) in your site.\n # So an interesting test here is: how fast is this? For a\n- # speed test, uncomment the next few lines. It basically\n- # tests having 3000 keywords, of which 50 are selected on a\n- # page. The related change in unicodeTestIn speeds this up\n+ # speed test, run the tests with 'export AT_UNICODETESTIN=3000'.\n+ # It basically tests having 3000 keywords, of which 50 are selected\n+ # on a page. The related change in unicodeTestIn speeds this up\n # from 42 to 15 seconds.\n- #vocab += [str(x) for x in range(3000)]\n- # for x in range(1000, 1050):\n- # self.assertEqual(self.portal.unicodeTestIn(str(x), vocab), True)\n+ # And 9 years later it is 4.4 seconds for only this first part.\n+ # And 0.03 seconds after some simple fixes to the script.\n+ number = int(os.getenv('AT_UNICODETESTIN', 0))\n+ if not number:\n+ return\n+ from time import time\n+ print('\\nTesting unicodeTestIn with {0} items, 50 selected.'.format(\n+ number))\n+ vocab += [str(x) for x in range(number)]\n+ value = [str(x) for x in range(1000, 1050)]\n+ time1 = time()\n+ for v in value:\n+ self.assertEqual(self.portal.unicodeTestIn(v, vocab), True)\n+ time2 = time()\n+ print('First test part finished in {0:.4f} seconds'.format(\n+ time2 - time1))\n+\n+ # This is actually more how it is used:\n+ # a large vocabulary, which is compared with a much smaller\n+ # list of selected items. Originally took 12.6 seconds for 3000 items.\n+ # And 0.2 seconds after some simple fixes.\n+ for v in vocab:\n+ # Some of these are True, others False, so we don't test the outcome.\n+ # We only call this to test the speed.\n+ self.portal.unicodeTestIn(v, value)\n+ time3 = time()\n+ print('Second test part finished in {0:.4f} seconds'.format(\n+ time3 - time2))\n \n def _test_widgets(self):\n doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')\ndiff --git a/news/125.bugfix b/news/125.bugfix\nnew file mode 100644\nindex 00000000..b992e988\n--- /dev/null\n+++ b/news/125.bugfix\n@@ -0,0 +1,2 @@\n+Fixed slowness in ``unicodeTestIn`` script used by keyword template.\n+[maurits]\n\\ No newline at end of file\n"

0 comments on commit a3ff903

Please sign in to comment.