|
1 #!/usr/bin/env python |
|
2 |
|
3 import os |
|
4 import threading |
|
5 from time import sleep |
|
6 import unittest |
|
7 |
|
8 import mozrunnertest |
|
9 |
|
10 |
|
11 class RunnerThread(threading.Thread): |
|
12 def __init__(self, runner, timeout=10): |
|
13 threading.Thread.__init__(self) |
|
14 self.runner = runner |
|
15 self.timeout = timeout |
|
16 |
|
17 def run(self): |
|
18 sleep(self.timeout) |
|
19 self.runner.stop() |
|
20 |
|
21 |
|
22 class MozrunnerInteractiveTestCase(mozrunnertest.MozrunnerTestCase): |
|
23 |
|
24 def test_run_interactive(self): |
|
25 """Bug 965183: Run process in interactive mode and call wait()""" |
|
26 pid = self.runner.start(interactive=True) |
|
27 self.pids.append(pid) |
|
28 |
|
29 thread = RunnerThread(self.runner, 5) |
|
30 self.threads.append(thread) |
|
31 thread.start() |
|
32 |
|
33 # This is a blocking call. So the process should be killed by the thread |
|
34 self.runner.wait() |
|
35 thread.join() |
|
36 self.assertFalse(self.runner.is_running()) |
|
37 |
|
38 def test_stop_interactive(self): |
|
39 """Bug 965183: Explicitely stop process in interactive mode""" |
|
40 pid = self.runner.start(interactive=True) |
|
41 self.pids.append(pid) |
|
42 |
|
43 self.runner.stop() |
|
44 |
|
45 def test_wait_after_process_finished(self): |
|
46 """Wait after the process has been stopped should not raise an error""" |
|
47 self.runner.start(interactive=True) |
|
48 sleep(5) |
|
49 self.runner.process_handler.kill() |
|
50 |
|
51 returncode = self.runner.wait(1) |
|
52 |
|
53 self.assertNotIn(returncode, [None, 0]) |
|
54 self.assertIsNotNone(self.runner.process_handler) |