Bug 1284405 - Better handling of --socket-timeout cli argument value. r?maja_zf
MozReview-Commit-ID: A9LjNJRe2Vm
--- 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