michael@0: #!/usr/bin/env python michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import os michael@0: import signal michael@0: michael@0: import mozrunnertest michael@0: michael@0: michael@0: class MozrunnerStopTestCase(mozrunnertest.MozrunnerTestCase): michael@0: michael@0: def test_stop_process(self): michael@0: """Stop the process and test properties""" michael@0: self.runner.start() michael@0: returncode = self.runner.stop() michael@0: michael@0: self.assertFalse(self.runner.is_running()) michael@0: self.assertNotIn(returncode, [None, 0]) michael@0: self.assertEqual(self.runner.returncode, returncode) michael@0: self.assertIsNotNone(self.runner.process_handler) michael@0: michael@0: self.assertEqual(self.runner.wait(1), returncode) michael@0: michael@0: def test_stop_before_start(self): michael@0: """Stop the process before it gets started should not raise an error""" michael@0: returncode = self.runner.stop() michael@0: michael@0: def test_stop_process_custom_signal(self): michael@0: """Stop the process via a custom signal and test properties""" michael@0: self.runner.start() michael@0: returncode = self.runner.stop(signal.SIGTERM) michael@0: michael@0: self.assertFalse(self.runner.is_running()) michael@0: self.assertNotIn(returncode, [None, 0]) michael@0: self.assertEqual(self.runner.returncode, returncode) michael@0: self.assertIsNotNone(self.runner.process_handler) michael@0: michael@0: self.assertEqual(self.runner.wait(1), returncode)