testing/mozbase/mozrunner/tests/test_interactive.py

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial