Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lite_bootstrap/bootstrappers/faststream_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


if import_checker.is_faststream_installed:
from faststream._internal.broker import BrokerUsecase
from faststream.asgi import AsgiFastStream, AsgiResponse
from faststream.asgi import get as handle_get

Expand Down Expand Up @@ -50,8 +49,7 @@ def __init__(

@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
class FastStreamConfig(HealthChecksConfig, LoggingConfig, OpentelemetryConfig, PrometheusConfig, SentryConfig):
application: "AsgiFastStream" = dataclasses.field(default_factory=lambda: AsgiFastStream())
broker: typing.Optional["BrokerUsecase[typing.Any, typing.Any]"] = None
application: "AsgiFastStream"
opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None
prometheus_middleware_cls: type[FastStreamPrometheusMiddlewareProtocol] | None = None
health_checks_additional_checker: typing.Callable[[], typing.Coroutine[bool, typing.Any, typing.Any]] | None = None
Expand Down Expand Up @@ -160,8 +158,6 @@ def is_ready(self) -> bool:

def __init__(self, bootstrap_config: FastStreamConfig) -> None:
super().__init__(bootstrap_config)
if self.bootstrap_config.broker:
self.bootstrap_config.application.set_broker(self.bootstrap_config.broker)
self.bootstrap_config.application.on_shutdown(self.teardown)

def _prepare_application(self) -> "AsgiFastStream":
Expand Down
12 changes: 10 additions & 2 deletions tests/test_faststream_bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import typing

import faststream.asgi
import pytest
import structlog
from faststream._internal.broker import BrokerUsecase
Expand Down Expand Up @@ -39,8 +40,12 @@ def build_faststream_config(
sentry_dsn="https://testdsn@localhost/1",
health_checks_path="/custom-health/",
logging_buffer_capacity=0,
broker=broker,
health_checks_additional_checker=health_checks_additional_checker,
application=faststream.asgi.AsgiFastStream(
broker,
asyncapi_path=faststream.asgi.AsyncAPIRoute("/docs/"),
specification=faststream.AsyncAPI(),
),
)


Expand All @@ -64,6 +69,9 @@ async def test_faststream_bootstrap(broker: RedisBroker) -> None:
response = test_client.get(bootstrap_config.prometheus_metrics_path)
assert response.status_code == status.HTTP_200_OK

response = test_client.get("/docs/")
assert response.status_code == status.HTTP_200_OK

assert not bootstrapper.is_bootstrapped


Expand Down Expand Up @@ -94,7 +102,7 @@ async def custom_checker() -> bool:

def test_faststream_bootstrapper_not_ready() -> None:
with emulate_package_missing("faststream"), pytest.raises(RuntimeError, match="faststream is not installed"):
FastStreamBootstrapper(bootstrap_config=FastStreamConfig())
FastStreamBootstrapper(bootstrap_config=FastStreamConfig(application=faststream.asgi.AsgiFastStream()))


@pytest.mark.parametrize(
Expand Down
Loading