Esempio n. 1
0
    def __init__(self, timeout: float = 60, delay: float = 10) -> None:
        elasticsearch_binary = os.getenv("DSS_TEST_ES_PATH", "elasticsearch")
        tempdir = tempfile.TemporaryDirectory()

        # Set Elasticsearch's initial and max heap to 1.6 GiB, 40% of what's available on Travis, according to
        # guidance from https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
        env = dict(os.environ, ES_JAVA_OPTIONS="-Xms1638m -Xmx1638m")

        # Work around https://github.com/travis-ci/travis-ci/issues/8408
        if '_JAVA_OPTIONS' in env:  # no coverage
            logger.warning(
                "_JAVA_OPTIONS is set. This may override the options just set via ES_JAVA_OPTIONS."
            )

        port = networking.unused_tcp_port()
        transport_port = networking.unused_tcp_port()

        args = [
            elasticsearch_binary, "-E", f"http.port={port}", "-E",
            f"transport.tcp.port={transport_port}", "-E",
            f"path.data={tempdir.name}", "-E", "logger.org.elasticsearch=" +
            ("info" if Config.debug_level() > 0 else "warn")
        ]
        logger.info("Running %r with environment %r", args, env)
        proc = subprocess.Popen(args, env=env)

        def check():
            status = proc.poll()
            if status is not None:
                tempdir.cleanup()
                raise ChildProcessError(
                    f"ES process died with status {status}")

        deadline = time.time() + timeout
        while True:
            check()
            time.sleep(delay)
            check()
            logger.info('Attempting to connect to ES instance at 127.0.0.1:%i',
                        port)
            try:
                sock = socket.create_connection(("127.0.0.1", port), 1)
            except (ConnectionRefusedError, socket.timeout):
                logger.debug(
                    'Failed connecting to ES instance at 127.0.0.1:%i',
                    port,
                    exc_info=True)
                if time.time() + delay > deadline:
                    proc.kill()
                    tempdir.cleanup()
                    raise
            else:
                sock.close()
                check()
                self.port = port
                self.proc = proc
                self.tempdir = tempdir
                break
Esempio n. 2
0
 def setUpClass(cls):
     super().setUpClass()
     cls.port = networking.unused_tcp_port()
     cls.server = cls.ThreadedHTTPServer((cls.address, cls.port),
                                         PostTestHandler)
     cls.server_thread = threading.Thread(target=cls._serve)
     cls.server_thread.start()
Esempio n. 3
0
 def __init__(self, handler_cls=SilentHandler):
     super().__init__(daemon=True)
     self._port = networking.unused_tcp_port()
     self._server = None
     self._server_ready = threading.Event()
     self._chalice_app = None
     self._handler_cls = handler_cls
Esempio n. 4
0
    def setUpClass(cls, timeout_seconds=10):
        dss_root_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..'))
        cls.port = networking.unused_tcp_port()
        cls.subprocess = subprocess.Popen([
            os.path.join(dss_root_path, "dss-api"),
            "--port",
            str(cls.port),
            "--log-level",
            "CRITICAL",
        ],
                                          cwd=dss_root_path)

        end_time = time.time() + timeout_seconds
        delay = 0.05
        while time.time() < end_time:
            try:
                with contextlib.closing(
                        socket.create_connection(("127.0.0.1", cls.port))):
                    pass
                break
            except ConnectionError:
                delay = max(1.0, delay * 2)
                time.sleep(delay)
                continue
def setUpModule():
    configure_test_logging()
    HTTPInfo.port = networking.unused_tcp_port()
    HTTPInfo.server = HTTPServer((HTTPInfo.address, HTTPInfo.port),
                                 GetTestHandler)
    HTTPInfo.make_url()
    HTTPInfo.thread = threading.Thread(target=HTTPInfo.server.serve_forever)
    HTTPInfo.thread.start()

    global randomdata
    randomdata = os.urandom(MB)
Esempio n. 6
0
 def __init__(self):
     super().__init__()
     self._port = networking.unused_tcp_port()
     self._server = None
     self._server_ready = threading.Event()
     self._chalice_app = None
Esempio n. 7
0
 def get_addr_port():
     addr = "127.0.0.1"
     port = networking.unused_tcp_port()
     return addr, port