Debian Codegraph @

testing/mozbase/mozrunner/tests/test_threads.py

raw
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/.
5
6 import mozunit
7
8
9 def test_process_start_via_thread(runner, create_thread):
10 """Start the runner via a thread"""
11 thread = create_thread(runner, True, 2)
12
13 thread.start()
14 thread.join()
15
16 assert runner.is_running()
17
18
19 def test_process_stop_via_multiple_threads(runner, create_thread):
20 """Stop the runner via multiple threads"""
21 runner.start()
22 threads = []
23 for i in range(5):
24 thread = create_thread(runner, False, 5)
25 threads.append(thread)
26 thread.start()
27
28 # Wait until the process has been stopped by another thread
29 for thread in threads:
30 thread.join()
31 returncode = runner.wait(1)
32
33 assert returncode not in [None, 0]
34 assert runner.returncode == returncode
35 assert runner.process_handler is not None
36 assert runner.wait(2) == returncode
37
38
39 def test_process_post_stop_via_thread(runner, create_thread):
40 """Stop the runner and try it again with a thread a bit later"""
41 runner.start()
42 thread = create_thread(runner, False, 5)
43 thread.start()
44
45 # Wait a bit to start the application gets started
46 runner.wait(1)
47 returncode = runner.stop()
48 thread.join()
49
50 assert returncode not in [None, 0]
51 assert runner.returncode == returncode
52 assert runner.process_handler is not None
53 assert runner.wait(2) == returncode
54
55
56 if __name__ == "__main__":
57 mozunit.main()