Example #1
0
 def StartServer(self, timeout=10):
     """Start TsProxy server and verify that it started.
 """
     cmd_line = [sys.executable, _TSPROXY_PATH]
     cmd_line.extend([
         '--port=0'
     ])  # Use port 0 so tsproxy picks a random available port.
     if self._host_ip:
         cmd_line.append('--desthost=%s' % self._host_ip)
     if self._http_port:
         cmd_line.append('--mapports=443:%s,*:%s' %
                         (self._https_port, self._http_port))
     logging.info('Tsproxy commandline: %r' % cmd_line)
     self._proc = subprocess.Popen(cmd_line,
                                   stdout=subprocess.PIPE,
                                   stdin=subprocess.PIPE,
                                   stderr=subprocess.PIPE,
                                   bufsize=1)
     atexit_with_log.Register(self.StopServer)
     try:
         py_utils.WaitFor(self._IsStarted, timeout)
         logging.info('TsProxy port: %s', self._port)
         self._is_running = True
     except py_utils.TimeoutException:
         # TODO(nedn): remove this debug log once crbug.com/766877 is resolved
         ps_util.ListAllSubprocesses()
         err = self.StopServer()
         raise RuntimeError('Error starting tsproxy: %s' % err)
Example #2
0
    def StartServer(self, timeout=10, retries=None):
        """Start TsProxy server and verify that it started.
    """
        del retries  # handled by the decorator
        cmd_line = [sys.executable, _TSPROXY_PATH]
        cmd_line.extend([
            '--port=0'
        ])  # Use port 0 so tsproxy picks a random available port.
        if self._host_ip:
            cmd_line.append('--desthost=%s' % self._host_ip)
        if self._http_port:
            cmd_line.append('--mapports=443:%s,*:%s' %
                            (self._https_port, self._http_port))
        logging.info('Tsproxy commandline: %r' % cmd_line)
        self._proc = subprocess.Popen(cmd_line,
                                      stdout=subprocess.PIPE,
                                      stdin=subprocess.PIPE,
                                      stderr=subprocess.PIPE,
                                      bufsize=1)
        self._non_blocking = False
        if fcntl:
            logging.info('fcntl is supported, try setting '
                         'non blocking I/O for the ts_proxy process')
            fd = self._proc.stdout.fileno()
            fl = fcntl.fcntl(fd, fcntl.F_GETFL)
            fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
            self._non_blocking = True

        atexit_with_log.Register(self.StopServer)
        try:
            py_utils.WaitFor(self._IsStarted, timeout)
            logging.info('TsProxy port: %s', self._port)
            self._is_running = True
        except py_utils.TimeoutException:
            # TODO(nedn): remove this debug log once crbug.com/766877 is resolved
            ps_util.ListAllSubprocesses()
            err = self.StopServer()
            if err:
                logging.error('Error stopping WPR server:\n%s', err)
            raise exceptions.Error(
                'Error starting tsproxy: timed out after %s seconds' % timeout)
Example #3
0
 def setUp(self):
     # TODO(nedn): remove this debug log once crbug.com/766877 is resolved
     if self._platform.GetOSName() == 'win':
         ps_util.ListAllSubprocesses()