Example #1
0
    def test_if_possible_to_separate_between_test_instance_and_other_process(
            self, popen_communicate_mock):

        port = 9001
        popen_communicate_mock.return_value = (self.ps_output(port), "")
        assert not is_port_used_by_another_process(9001)

        free_port = port + 1
        while is_port_used_by_another_process(free_port):
            free_port += 1
        self._start_http_server_thread(free_port)
        assert is_port_used_by_another_process(free_port)
Example #2
0
    def test_if_possible_to_separate_between_test_instance_and_other_process(
            self,
            popen_communicate_mock):

        port = 9001
        popen_communicate_mock.return_value = (self.ps_output(port), "")
        assert not is_port_used_by_another_process(9001)

        free_port = port + 1
        while is_port_used_by_another_process(free_port):
            free_port += 1
        self._start_http_server_thread(free_port)
        assert is_port_used_by_another_process(free_port)
Example #3
0
def start_rp_process(port, command, working_directory=None):
    failed_to_start_message = "Failed to start test instance %s." % get_base_url(
        port)

    if is_port_used_by_another_process(port):
        log_info = "Port %s is used by another process" % port
        raise PortUsedByOtherProcess(failed_to_start_message,
                                     log_info=log_info)

    try:
        p = subprocess.Popen(command,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             cwd=working_directory)
    except Exception as ex:
        raise SubProcessFailed(
            failed_to_start_message,
            log_info="Failed to run oprp script: %s Error message: %s" %
            (command[0], ex.message))

    check_if_oprp_started(port, get_base_url(port))

    return_code = p.poll()
    if return_code is not None:
        raise NoResponseException(
            failed_to_start_message,
            log_info="Return code %s != None so the process did not "
            "start correctly. Command executed: %s" % (return_code, command))
Example #4
0
def start_rp_process(port, command, working_directory=None):
    failed_to_start_message = "Failed to start test instance %s." % get_base_url(port)

    if is_port_used_by_another_process(port):
        log_info = "Port %s is used by another process" % port
        raise PortUsedByOtherProcess(failed_to_start_message,
                                     log_info=log_info)

    try:
        p = subprocess.Popen(command,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             cwd=working_directory)
    except Exception as ex:
        raise SubProcessFailed(failed_to_start_message,
                               log_info="Failed to run oprp script: %s Error message: %s"
                                        % (command[0], ex.message))

    check_if_oprp_started(port, get_base_url(port))

    return_code = p.poll()
    if return_code is not None:
        raise NoResponseException(failed_to_start_message,
                                  log_info="Return code %s != None so the process did not "
                                           "start correctly. Command executed: %s"
                                           % (return_code, command))
Example #5
0
 def test_trows_exception_while_running_command(self, run_command_mock):
     run_command_mock.side_effect = Exception()
     port_is_used = is_port_used_by_another_process(8000)
     assert port_is_used
Example #6
0
 def test_trows_exception_while_running_command(self, run_command_mock):
     run_command_mock.side_effect = Exception()
     port_is_used = is_port_used_by_another_process(8000)
     assert port_is_used