RESOLVED FIXED 169385
webkitpy: Add unit test to prevent breakage of EWS
https://bugs.webkit.org/show_bug.cgi?id=169385
Summary webkitpy: Add unit test to prevent breakage of EWS
Jonathan Bedard
Reported 2017-03-08 14:29:56 PST
We should have a test to prevent something like <http://trac.webkit.org/changeset/213545> from happening in the future.
Attachments
Patch (2.02 KB, patch)
2017-03-08 14:31 PST, Jonathan Bedard
no flags
Patch (1.96 KB, patch)
2017-03-08 16:03 PST, Jonathan Bedard
no flags
Patch (1.96 KB, patch)
2017-03-08 16:04 PST, Jonathan Bedard
no flags
Patch for landing (2.14 KB, patch)
2017-03-09 10:28 PST, Jonathan Bedard
no flags
Jonathan Bedard
Comment 1 2017-03-08 14:31:02 PST
Srinivasan Vijayaraghavan
Comment 2 2017-03-08 15:33:17 PST
Comment on attachment 303846 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=303846&action=review Nice test! I'd suggest making more use of python's in-built types to keep the code more readable, something like below: > Tools/Scripts/webkitpy/tool/commands/earlywarningsystem_unittest.py:177 > + expected_names = [ > + 'gtk-wk2-ews', > + 'win-ews', > + 'ios-ews', > + 'ios-sim-ews', > + 'mac-ews', > + 'mac-wk2-ews', > + 'mac-debug-ews', > + 'mac-32bit-ews', > + 'jsc-ews', > + ] > + classes = AbstractEarlyWarningSystem.load_ews_classes() > + for name in expected_names: > + flag = False > + for cls in classes: > + if name == cls.name: > + flag = True > + break > + if not flag: > + raise Exception("'{}' is not a valid EWS command but is used by EWS's infrastructure".format(name)) expected_names = set([ 'gtk-wk2-ews', 'gtk-wk2-ews', 'win-ews', 'ios-ews', 'ios-sim-ews', 'mac-ews', 'mac-wk2-ews', 'mac-debug-ews', 'mac-32bit-ews', 'jsc-ews', ]) classes = AbstractEarlyWarningSystem.load_ews_classes() names = set([cls.name for cls in classes]) unexpected_names = names - expected_names if unexpected_names: raise Exception("'{}' is not a valid EWS command but is used by EWS's infrastructure".format(unexpected_names.pop()))
Srinivasan Vijayaraghavan
Comment 3 2017-03-08 15:53:19 PST
Actually, since we're ultimately inheriting from unittest.TestCase, raise an AssertionError("message") instead of the generic Exception.
Jonathan Bedard
Comment 4 2017-03-08 16:03:39 PST
Jonathan Bedard
Comment 5 2017-03-08 16:04:58 PST
Alexey Proskuryakov
Comment 6 2017-03-09 09:35:12 PST
Comment on attachment 303859 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=303859&action=review > Tools/Scripts/webkitpy/tool/commands/earlywarningsystem_unittest.py:157 > + # These are the names EWS's infrastructure expects, check that they work Can the test get the names from ews.json? Those are the ones that the infrastructure really expects. > Tools/Scripts/webkitpy/tool/commands/earlywarningsystem_unittest.py:169 > + classes = AbstractEarlyWarningSystem.load_ews_classes() Is this a persistent change that can affect other tests? Adding new globally defined classes seems less than ideal if that can be avoided. But other EWS tests already do the same, so I think that the patch doesn't make it worse.
Jonathan Bedard
Comment 7 2017-03-09 09:42:48 PST
Comment on attachment 303859 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=303859&action=review >> Tools/Scripts/webkitpy/tool/commands/earlywarningsystem_unittest.py:157 >> + # These are the names EWS's infrastructure expects, check that they work > > Can the test get the names from ews.json? Those are the ones that the infrastructure really expects. So this is actually exactly what is being tested here. 'load_ews_classes()' reads from ews.json and parses the names of the ports themselves and uses that combination to construct commands. This list of commands is essentially what our EWS infrastructure currently expects to be able to run. If we intend to change this infrastructure, this set would need to be modified. I think this is the right way to test this, though. It is not intuitive that changing the name of a port in webkitpy could break EWS because changing the port name will change the EWS command.
Dean Johnson
Comment 8 2017-03-09 10:04:17 PST
Comment on attachment 303859 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=303859&action=review > Tools/Scripts/webkitpy/tool/commands/earlywarningsystem_unittest.py:158 > + expected_names = set([ This could be constructed without a set cast by using {} (Python's set syntax). It would look like the following expected_names = { 'gtk-wk2-ews', ...., 'jsc-ews', } > Tools/Scripts/webkitpy/tool/commands/earlywarningsystem_unittest.py:170 > + names = set([cls.name for cls in classes]) Similarly: names = {cls.name for cls in classes}
Jonathan Bedard
Comment 9 2017-03-09 10:28:40 PST
Created attachment 303932 [details] Patch for landing
Srinivasan Vijayaraghavan
Comment 10 2017-03-09 10:36:03 PST
I didn't suggest the set literal syntax since it's 2.7 only, but I guess the bots have all been updated now.
WebKit Commit Bot
Comment 11 2017-03-09 11:08:41 PST
Comment on attachment 303932 [details] Patch for landing Clearing flags on attachment: 303932 Committed r213651: <http://trac.webkit.org/changeset/213651>
WebKit Commit Bot
Comment 12 2017-03-09 11:08:45 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.