Exemplo n.º 1
0
 def start(self, retry_spec: Optional[RetrySpec] = None):
     super().start()
     retry_spec = retry_spec or RetrySpec(attempts=20)
     conn = retry_spec.retry(self.connection,
                             (AMQPConnectionError, ConnectionError))
     conn.close()
     return self
Exemplo n.º 2
0
 def start(self, retry_spec: Optional[RetrySpec] = None):
     super().start()
     retry_spec = retry_spec or RetrySpec(attempts=20)
     with retry_spec.retry(self.consumer,
                           (KafkaError, ConnectionError, ValueError)):
         pass
     return self
Exemplo n.º 3
0
 def start(self, retry_spec: Optional[RetrySpec] = None):
     super().start()
     with self.client() as client:
         retry_spec = retry_spec or RetrySpec(attempts=10)
         retry_spec.retry(client.ping, RedisConnectionError)
     self.started = True
     return self
Exemplo n.º 4
0
    def start(self, retry_spec: Optional[RetrySpec] = None) -> WebServer:
        if self._serve_thread.is_alive():
            raise RuntimeError('thread cannot be started twice')
        with mute_uvicorn_log():
            self._serve_thread.start()
            with self.patch_http_endpoint('GET',
                                          '/__yellowbox/ping',
                                          side_effect=PlainTextResponse('')):
                retry_spec = retry_spec or RetrySpec(interval=0.1, timeout=5)
                retry_spec.retry(
                    lambda: get(self.local_url() + '/__yellowbox/ping').
                    raise_for_status(), (ConnectionError, HTTPError))

        # add all the class endpoints
        for name, template in type(self)._CLASS_ENDPOINT_TEMPLATES.items():
            ep: Union[MockHTTPEndpoint, MockWSEndpoint]
            if isinstance(template, HTTPEndpointTemplate):
                ep = template.construct(self)
                self.add_http_endpoint(ep)
            else:
                assert isinstance(template, WSEndpointTemplate)
                ep = template.construct(self)
                self.add_ws_endpoint(ep)
            setattr(self, name, ep)

        return super().start()
Exemplo n.º 5
0
 def start(self, retry_spec: Optional[RetrySpec] = None):
     with self.patch_route('GET', '/health', 200):
         self.server_thread.start()
         retry_spec = retry_spec or RetrySpec(attempts=10)
         retry_spec.retry(
             lambda: requests.get(self.local_url + '/health').
             raise_for_status(), (ConnectionError, HTTPError))
     return super(HttpService, self).start()
Exemplo n.º 6
0
    def start(self, retry_spec: Optional[RetrySpec] = None, **kwargs):
        super().start(**kwargs)

        def health_check(client: httpx.Client):
            client.get(f"http://localhost:{self.client_port()}/api/health"
                       ).raise_for_status()

        with httpx.Client() as client:
            retry_spec = retry_spec or RetrySpec(attempts=10)
            retry_spec.retry(partial(health_check, client), httpx.RequestError)
Exemplo n.º 7
0
    def start(self, retry_spec: Optional[RetrySpec] = None):
        super().start()

        def check_ready():
            if b"Azurite Blob service successfully listens on" not in self.container.logs():
                raise _ResourceNotReady

        retry_spec = retry_spec or RetrySpec(attempts=10)

        retry_spec.retry(check_ready, _ResourceNotReady)
        return self
Exemplo n.º 8
0
    def start(self, retry_spec: Optional[RetrySpec] = None):
        super().start()

        retry_spec = retry_spec or RetrySpec(attempts=10)

        def check_health():
            with self.client() as client:
                client.lookup_token()

        retry_spec.retry(check_health, (VaultError, ConnectionError))
        with self.client() as client:
            client.sys.enable_auth_method('userpass')
        self.started = True
        return self