summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozrunner/tests
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/mozbase/mozrunner/tests
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mozbase/mozrunner/tests')
-rw-r--r--testing/mozbase/mozrunner/tests/manifest.ini7
-rw-r--r--testing/mozbase/mozrunner/tests/mozrunnertest.py34
-rw-r--r--testing/mozbase/mozrunner/tests/test_crash.py37
-rw-r--r--testing/mozbase/mozrunner/tests/test_interactive.py53
-rw-r--r--testing/mozbase/mozrunner/tests/test_start.py45
-rw-r--r--testing/mozbase/mozrunner/tests/test_states.py18
-rw-r--r--testing/mozbase/mozrunner/tests/test_stop.py39
-rw-r--r--testing/mozbase/mozrunner/tests/test_threads.py73
-rw-r--r--testing/mozbase/mozrunner/tests/test_wait.py29
9 files changed, 335 insertions, 0 deletions
diff --git a/testing/mozbase/mozrunner/tests/manifest.ini b/testing/mozbase/mozrunner/tests/manifest.ini
new file mode 100644
index 000000000..62af8fb30
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/manifest.ini
@@ -0,0 +1,7 @@
+[test_crash.py]
+[test_interactive.py]
+[test_start.py]
+[test_states.py]
+[test_stop.py]
+[test_threads.py]
+[test_wait.py]
diff --git a/testing/mozbase/mozrunner/tests/mozrunnertest.py b/testing/mozbase/mozrunner/tests/mozrunnertest.py
new file mode 100644
index 000000000..33f51031f
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/mozrunnertest.py
@@ -0,0 +1,34 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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 os
+import unittest
+
+import mozprofile
+import mozrunner
+
+
+@unittest.skipIf(not os.environ.get('BROWSER_PATH'),
+ 'No binary has been specified.')
+class MozrunnerTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.pids = []
+ self.threads = []
+
+ self.profile = mozprofile.FirefoxProfile()
+ self.runner = mozrunner.FirefoxRunner(os.environ['BROWSER_PATH'],
+ profile=self.profile)
+
+ def tearDown(self):
+ for thread in self.threads:
+ thread.join()
+
+ self.runner.cleanup()
+
+ # Clean-up any left over and running processes
+ for pid in self.pids:
+ # TODO: Bug 925408
+ # mozprocess is not able yet to kill specific processes
+ pass
diff --git a/testing/mozbase/mozrunner/tests/test_crash.py b/testing/mozbase/mozrunner/tests/test_crash.py
new file mode 100644
index 000000000..455fc5f72
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/test_crash.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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 mock
+
+import mozrunnertest
+
+
+class MozrunnerCrashTestCase(mozrunnertest.MozrunnerTestCase):
+
+ @mock.patch('mozcrash.log_crashes', return_value=2)
+ def test_crash_count_with_logger(self, log_crashes):
+ self.assertEqual(self.runner.crashed, 0)
+ self.assertEqual(self.runner.check_for_crashes(), 2)
+ self.assertEqual(self.runner.crashed, 2)
+ self.assertEqual(self.runner.check_for_crashes(), 2)
+ self.assertEqual(self.runner.crashed, 4)
+
+ log_crashes.return_value = 0
+ self.assertEqual(self.runner.check_for_crashes(), 0)
+ self.assertEqual(self.runner.crashed, 4)
+
+ @mock.patch('mozcrash.check_for_crashes', return_value=2)
+ def test_crash_count_without_logger(self, check_for_crashes):
+ self.runner.logger = None
+
+ self.assertEqual(self.runner.crashed, 0)
+ self.assertEqual(self.runner.check_for_crashes(), 2)
+ self.assertEqual(self.runner.crashed, 2)
+ self.assertEqual(self.runner.check_for_crashes(), 2)
+ self.assertEqual(self.runner.crashed, 4)
+
+ check_for_crashes.return_value = 0
+ self.assertEqual(self.runner.check_for_crashes(), 0)
+ self.assertEqual(self.runner.crashed, 4)
diff --git a/testing/mozbase/mozrunner/tests/test_interactive.py b/testing/mozbase/mozrunner/tests/test_interactive.py
new file mode 100644
index 000000000..fe83bf80e
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/test_interactive.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+import threading
+from time import sleep
+
+import mozrunnertest
+
+
+class RunnerThread(threading.Thread):
+
+ def __init__(self, runner, timeout=10):
+ threading.Thread.__init__(self)
+ self.runner = runner
+ self.timeout = timeout
+
+ def run(self):
+ sleep(self.timeout)
+ self.runner.stop()
+
+
+class MozrunnerInteractiveTestCase(mozrunnertest.MozrunnerTestCase):
+
+ def test_run_interactive(self):
+ """Bug 965183: Run process in interactive mode and call wait()"""
+ pid = self.runner.start(interactive=True)
+ self.pids.append(pid)
+
+ thread = RunnerThread(self.runner, 5)
+ self.threads.append(thread)
+ thread.start()
+
+ # This is a blocking call. So the process should be killed by the thread
+ self.runner.wait()
+ thread.join()
+ self.assertFalse(self.runner.is_running())
+
+ def test_stop_interactive(self):
+ """Bug 965183: Explicitely stop process in interactive mode"""
+ pid = self.runner.start(interactive=True)
+ self.pids.append(pid)
+
+ self.runner.stop()
+
+ def test_wait_after_process_finished(self):
+ """Wait after the process has been stopped should not raise an error"""
+ self.runner.start(interactive=True)
+ sleep(5)
+ self.runner.process_handler.kill()
+
+ returncode = self.runner.wait(1)
+
+ self.assertNotIn(returncode, [None, 0])
+ self.assertIsNotNone(self.runner.process_handler)
diff --git a/testing/mozbase/mozrunner/tests/test_start.py b/testing/mozbase/mozrunner/tests/test_start.py
new file mode 100644
index 000000000..396584e00
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/test_start.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+from time import sleep
+
+import mozrunnertest
+
+
+class MozrunnerStartTestCase(mozrunnertest.MozrunnerTestCase):
+
+ def test_start_process(self):
+ """Start the process and test properties"""
+ self.assertIsNone(self.runner.process_handler)
+
+ self.runner.start()
+
+ self.assertTrue(self.runner.is_running())
+ self.assertIsNotNone(self.runner.process_handler)
+
+ def test_start_process_called_twice(self):
+ """Start the process twice and test that first process is gone"""
+ self.runner.start()
+ # Bug 925480
+ # Make a copy until mozprocess can kill a specific process
+ process_handler = self.runner.process_handler
+
+ self.runner.start()
+
+ try:
+ self.assertNotIn(process_handler.wait(1), [None, 0])
+ finally:
+ process_handler.kill()
+
+ def test_start_with_timeout(self):
+ """Start the process and set a timeout"""
+ self.runner.start(timeout=2)
+ sleep(5)
+
+ self.assertFalse(self.runner.is_running())
+
+ def test_start_with_outputTimeout(self):
+ """Start the process and set a timeout"""
+ self.runner.start(outputTimeout=2)
+ sleep(15)
+
+ self.assertFalse(self.runner.is_running())
diff --git a/testing/mozbase/mozrunner/tests/test_states.py b/testing/mozbase/mozrunner/tests/test_states.py
new file mode 100644
index 000000000..865e12263
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/test_states.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+import mozrunner
+
+import mozrunnertest
+
+
+class MozrunnerStatesTestCase(mozrunnertest.MozrunnerTestCase):
+
+ def test_errors_before_start(self):
+ """Bug 965714: Not started errors before start() is called"""
+
+ def test_returncode():
+ return self.runner.returncode
+
+ self.assertRaises(mozrunner.RunnerNotStartedError, self.runner.is_running)
+ self.assertRaises(mozrunner.RunnerNotStartedError, test_returncode)
+ self.assertRaises(mozrunner.RunnerNotStartedError, self.runner.wait)
diff --git a/testing/mozbase/mozrunner/tests/test_stop.py b/testing/mozbase/mozrunner/tests/test_stop.py
new file mode 100644
index 000000000..102d57a4e
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/test_stop.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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 signal
+
+import mozrunnertest
+
+
+class MozrunnerStopTestCase(mozrunnertest.MozrunnerTestCase):
+
+ def test_stop_process(self):
+ """Stop the process and test properties"""
+ self.runner.start()
+ returncode = self.runner.stop()
+
+ self.assertFalse(self.runner.is_running())
+ self.assertNotIn(returncode, [None, 0])
+ self.assertEqual(self.runner.returncode, returncode)
+ self.assertIsNotNone(self.runner.process_handler)
+
+ self.assertEqual(self.runner.wait(1), returncode)
+
+ def test_stop_before_start(self):
+ """Stop the process before it gets started should not raise an error"""
+ self.runner.stop()
+
+ def test_stop_process_custom_signal(self):
+ """Stop the process via a custom signal and test properties"""
+ self.runner.start()
+ returncode = self.runner.stop(signal.SIGTERM)
+
+ self.assertFalse(self.runner.is_running())
+ self.assertNotIn(returncode, [None, 0])
+ self.assertEqual(self.runner.returncode, returncode)
+ self.assertIsNotNone(self.runner.process_handler)
+
+ self.assertEqual(self.runner.wait(1), returncode)
diff --git a/testing/mozbase/mozrunner/tests/test_threads.py b/testing/mozbase/mozrunner/tests/test_threads.py
new file mode 100644
index 000000000..4b9b4cfc3
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/test_threads.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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 threading
+from time import sleep
+
+import mozrunnertest
+
+
+class RunnerThread(threading.Thread):
+
+ def __init__(self, runner, do_start, timeout=10):
+ threading.Thread.__init__(self)
+ self.runner = runner
+ self.timeout = timeout
+ self.do_start = do_start
+
+ def run(self):
+ sleep(self.timeout)
+ if self.do_start:
+ self.runner.start()
+ else:
+ self.runner.stop()
+
+
+class MozrunnerThreadsTestCase(mozrunnertest.MozrunnerTestCase):
+
+ def test_process_start_via_thread(self):
+ """Start the runner via a thread"""
+ thread = RunnerThread(self.runner, True, 2)
+ self.threads.append(thread)
+
+ thread.start()
+ thread.join()
+
+ self.assertTrue(self.runner.is_running())
+
+ def test_process_stop_via_multiple_threads(self):
+ """Stop the runner via multiple threads"""
+ self.runner.start()
+ for i in range(5):
+ thread = RunnerThread(self.runner, False, 5)
+ self.threads.append(thread)
+ thread.start()
+
+ # Wait until the process has been stopped by another thread
+ for thread in self.threads:
+ thread.join()
+ returncode = self.runner.wait(2)
+
+ self.assertNotIn(returncode, [None, 0])
+ self.assertEqual(self.runner.returncode, returncode)
+ self.assertIsNotNone(self.runner.process_handler)
+ self.assertEqual(self.runner.wait(10), returncode)
+
+ def test_process_post_stop_via_thread(self):
+ """Stop the runner and try it again with a thread a bit later"""
+ self.runner.start()
+ thread = RunnerThread(self.runner, False, 5)
+ self.threads.append(thread)
+ thread.start()
+
+ # Wait a bit to start the application gets started
+ self.runner.wait(2)
+ returncode = self.runner.stop()
+ thread.join()
+
+ self.assertNotIn(returncode, [None, 0])
+ self.assertEqual(self.runner.returncode, returncode)
+ self.assertIsNotNone(self.runner.process_handler)
+ self.assertEqual(self.runner.wait(10), returncode)
diff --git a/testing/mozbase/mozrunner/tests/test_wait.py b/testing/mozbase/mozrunner/tests/test_wait.py
new file mode 100644
index 000000000..8da1efc3c
--- /dev/null
+++ b/testing/mozbase/mozrunner/tests/test_wait.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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 mozrunnertest
+
+
+class MozrunnerWaitTestCase(mozrunnertest.MozrunnerTestCase):
+
+ def test_wait_while_running(self):
+ """Wait for the process while it is running"""
+ self.runner.start()
+ returncode = self.runner.wait(1)
+
+ self.assertTrue(self.runner.is_running())
+ self.assertEqual(returncode, None)
+ self.assertEqual(self.runner.returncode, returncode)
+ self.assertIsNotNone(self.runner.process_handler)
+
+ def test_wait_after_process_finished(self):
+ """Bug 965714: wait() after stop should not raise an error"""
+ self.runner.start()
+ self.runner.process_handler.kill()
+
+ returncode = self.runner.wait(1)
+
+ self.assertNotIn(returncode, [None, 0])
+ self.assertIsNotNone(self.runner.process_handler)