Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 #!/usr/bin/env python
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 # You can obtain one at http://mozilla.org/MPL/2.0/.
6 import threading
7 from time import sleep
9 import mozrunnertest
12 class RunnerThread(threading.Thread):
13 def __init__(self, runner, do_start, timeout=10):
14 threading.Thread.__init__(self)
15 self.runner = runner
16 self.timeout = timeout
17 self.do_start = do_start
19 def run(self):
20 sleep(self.timeout)
21 if self.do_start:
22 self.runner.start()
23 else:
24 self.runner.stop()
27 class MozrunnerThreadsTestCase(mozrunnertest.MozrunnerTestCase):
29 def test_process_start_via_thread(self):
30 """Start the runner via a thread"""
31 thread = RunnerThread(self.runner, True, 2)
32 self.threads.append(thread)
34 thread.start()
35 thread.join()
37 self.assertTrue(self.runner.is_running())
39 def test_process_stop_via_multiple_threads(self):
40 """Stop the runner via multiple threads"""
41 self.runner.start()
42 for i in range(5):
43 thread = RunnerThread(self.runner, False, 5)
44 self.threads.append(thread)
45 thread.start()
47 # Wait until the process has been stopped by another thread
48 for thread in self.threads:
49 thread.join()
50 returncode = self.runner.wait(2)
52 self.assertNotIn(returncode, [None, 0])
53 self.assertEqual(self.runner.returncode, returncode)
54 self.assertIsNotNone(self.runner.process_handler)
55 self.assertEqual(self.runner.wait(10), returncode)
57 def test_process_post_stop_via_thread(self):
58 """Stop the runner and try it again with a thread a bit later"""
59 self.runner.start()
60 thread = RunnerThread(self.runner, False, 5)
61 self.threads.append(thread)
62 thread.start()
64 # Wait a bit to start the application gets started
65 self.runner.wait(2)
66 returncode = self.runner.stop()
67 thread.join()
69 self.assertNotIn(returncode, [None, 0])
70 self.assertEqual(self.runner.returncode, returncode)
71 self.assertIsNotNone(self.runner.process_handler)
72 self.assertEqual(self.runner.wait(10), returncode)