Bug 1284405 - Better handling of --socket-timeout cli argument value. r=maja_zf
authorNelson João Morais <njmorais@gmail.com>
Tue, 19 Jul 2016 23:34:46 +0100
changeset 346137 bc563c2d69012ccbd04e754c8d0440fb8e66a9e5
parent 346136 3ec6380fca8207fa199693206a3ca24975bf9833
child 346138 4a8156e1267732f57c9013349b6a49688b3857e3
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1284405
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1284405 - Better handling of --socket-timeout cli argument value. r=maja_zf MozReview-Commit-ID: A9LjNJRe2Vm
testing/marionette/harness/marionette/runner/base.py
testing/marionette/harness/marionette/tests/harness_unit/test_marionette_runner.py
--- a/testing/marionette/harness/marionette/runner/base.py
+++ b/testing/marionette/harness/marionette/runner/base.py
@@ -341,16 +341,17 @@ class BaseMarionetteArguments(ArgumentPa
         self.add_argument('--jsdebugger',
                         action='store_true',
                         default=False,
                         help='Enable the jsdebugger for marionette javascript.')
         self.add_argument('--pydebugger',
                         help='Enable python post-mortem debugger when a test fails.'
                              ' Pass in the debugger you want to use, eg pdb or ipdb.')
         self.add_argument('--socket-timeout',
+                        type=float,
                         default=self.socket_timeout_default,
                         help='Set the global timeout for marionette socket operations.')
         self.add_argument('--disable-e10s',
                         action='store_false',
                         dest='e10s',
                         default=True,
                         help='Disable e10s when running marionette tests.')
         self.add_argument('--tag',
--- a/testing/marionette/harness/marionette/tests/harness_unit/test_marionette_runner.py
+++ b/testing/marionette/harness/marionette/tests/harness_unit/test_marionette_runner.py
@@ -2,16 +2,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 import pytest
 from mock import patch, Mock, DEFAULT, mock_open, MagicMock
 
 from marionette.runtests import (
     MarionetteTestRunner,
     MarionetteHarness,
+    MarionetteArguments,
     cli
 )
 from marionette.runner import MarionetteTestResult
 from marionette_driver.marionette import Marionette
 
 # avoid importing MarionetteJSTestCase to prevent pytest from
 # collecting and running it as part of this test suite
 import marionette.marionette_test as marionette_test
@@ -200,16 +201,39 @@ def test_call_harness_with_parsed_args_y
         'marionette.runtests.MarionetteHarness.parse_args'
     ) as parse_args:
         failed_or_crashed = MarionetteHarness(runner_class,
                                               args=mach_parsed_kwargs).run()
         parse_args.assert_not_called()
     assert failed_or_crashed == sum(num_fails_crashed)
 
 
+@pytest.mark.parametrize("sock_timeout_value", ['A', '10', '1B-', '1C2', '44.35'])
+def test_parse_arg_socket_timeout_with_multiple_values(sock_timeout_value):
+    argv = ['marionette', '--socket-timeout', sock_timeout_value]
+    parser = MarionetteArguments()
+
+    def _is_float_convertible(value):
+        try:
+            float(value)
+            return True
+        except:
+            return False
+
+    if not _is_float_convertible(sock_timeout_value):
+        # should raising exception, since sock_timeout must be convertible to float.
+        with pytest.raises(SystemExit) as ex:
+            parser.parse_args(args=argv)
+        assert ex.value.code == 2
+    else:
+        # should pass without raising exception.
+        args = parser.parse_args(args=argv)
+        assert hasattr(args, 'socket_timeout') and args.socket_timeout == float(sock_timeout_value)
+
+
 def test_call_harness_with_no_args_yields_num_failures(runner_class):
     with patch(
         'marionette.runtests.MarionetteHarness.parse_args'
     ) as parse_args:
         parse_args.return_value = {'tests': []}
         failed_or_crashed = MarionetteHarness(runner_class).run()
         assert parse_args.call_count == 1
     assert failed_or_crashed == 0