示例#1
0
    def test_filters_empty_strings_from_command_args_when_shell_is_true(self):
        popen_calls = self.exit_stack.enter_context(self.swap_popen())
        logs = self.exit_stack.enter_context(self.capture_logging())

        proc = self.exit_stack.enter_context(servers.managed_process(
            ['', 'a', '', 1], timeout_secs=10, shell=True))
        self.exit_stack.close()

        self.assert_proc_was_managed_as_expected(logs, proc.pid)
        self.assertEqual(popen_calls, [self.POPEN_CALL('a 1', {'shell': True})])
示例#2
0
    def test_respects_processes_that_are_killed_early(self):
        self.exit_stack.enter_context(self.swap_popen())
        logs = self.exit_stack.enter_context(self.capture_logging())

        proc = self.exit_stack.enter_context(
            servers.managed_process(['a'], timeout_secs=10))
        time.sleep(1)
        proc.kill()
        proc.wait()
        self.exit_stack.close()

        self.assert_proc_was_managed_as_expected(
            logs, proc.pid, manager_should_have_sent_terminate_signal=False)
示例#3
0
    def test_reports_killed_processes_as_warnings(self):
        self.exit_stack.enter_context(self.swap_popen(unresponsive=True))
        logs = self.exit_stack.enter_context(self.capture_logging())

        proc = self.exit_stack.enter_context(
            servers.managed_process(['a'], timeout_secs=10))
        self.exit_stack.close()

        self.assert_proc_was_managed_as_expected(
            logs,
            proc.pid,
            manager_should_have_sent_terminate_signal=True,
            manager_should_have_sent_kill_signal=True)
示例#4
0
    def test_does_not_raise_when_exit_fails(self):
        self.exit_stack.enter_context(self.swap_popen())
        self.exit_stack.enter_context(self.swap_to_always_raise(
            psutil, 'wait_procs', error=Exception('uh-oh')))
        logs = self.exit_stack.enter_context(self.capture_logging(
            min_level=logging.ERROR))

        self.exit_stack.enter_context(servers.managed_process(['a', 'bc']))
        # Should not raise.
        self.exit_stack.close()

        self.assert_matches_regexps(logs, [
            r'Failed to stop Process\(pid=1\) gracefully!\n'
            r'Traceback \(most recent call last\):\n'
            r'.*'
            r'Exception: uh-oh',
        ])