@@ -21,7 +21,10 @@ def broker() -> RedisBroker:
2121 return RedisBroker ()
2222
2323
24- def build_faststream_config (broker : BrokerUsecase [typing .Any , typing .Any ] | None = None ) -> FastStreamConfig :
24+ def build_faststream_config (
25+ broker : BrokerUsecase [typing .Any , typing .Any ] | None = None ,
26+ health_checks_additional_checker : typing .Callable [[], typing .Coroutine [bool , typing .Any , typing .Any ]] | None = None ,
27+ ) -> FastStreamConfig :
2528 return FastStreamConfig (
2629 service_name = "microservice" ,
2730 service_version = "2.0.0" ,
@@ -37,6 +40,7 @@ def build_faststream_config(broker: BrokerUsecase[typing.Any, typing.Any] | None
3740 health_checks_path = "/custom-health/" ,
3841 logging_buffer_capacity = 0 ,
3942 broker = broker ,
43+ health_checks_additional_checker = health_checks_additional_checker ,
4044 )
4145
4246
@@ -74,6 +78,20 @@ async def test_faststream_bootstrap_health_check_wo_broker() -> None:
7478 assert response .text == "Service is unhealthy"
7579
7680
81+ async def test_faststream_bootstrap_additional_health_checker (broker : RedisBroker ) -> None :
82+ async def custom_checker () -> bool :
83+ return False
84+
85+ bootstrap_config = build_faststream_config (broker = broker , health_checks_additional_checker = custom_checker )
86+ bootstrapper = FastStreamBootstrapper (bootstrap_config = bootstrap_config )
87+ application = bootstrapper .bootstrap ()
88+ test_client = TestClient (app = application )
89+
90+ response = test_client .get (bootstrap_config .health_checks_path )
91+ assert response .status_code == status .HTTP_500_INTERNAL_SERVER_ERROR
92+ assert response .text == "Service is unhealthy"
93+
94+
7795def test_faststream_bootstrapper_not_ready () -> None :
7896 with emulate_package_missing ("faststream" ), pytest .raises (RuntimeError , match = "faststream is not installed" ):
7997 FastStreamBootstrapper (bootstrap_config = FastStreamConfig ())
0 commit comments