@@ -1008,30 +1008,47 @@ def _(celery_app: Celery) -> None: ...
10081008
10091009
10101010@pytest .fixture
1011- def storage_worker_mode (app_environment : EnvVarsDict , monkeypatch : pytest .MonkeyPatch ):
1012- monkeypatch .setenv ("STORAGE_WORKER_MODE" , "true" )
1013- monkeypatch .setenv ("CELERY_POOL" , "threads" )
1011+ def app_server_factory_with_worker_mode (
1012+ enable_tracing ,
1013+ app_environment : EnvVarsDict ,
1014+ enabled_rabbitmq : RabbitSettings ,
1015+ sqlalchemy_async_engine : AsyncEngine ,
1016+ postgres_host_config : dict [str , str ],
1017+ mocked_s3_server_envs : EnvVarsDict ,
1018+ datcore_adapter_service_mock : respx .MockRouter ,
1019+ mocked_redis_server : None ,
1020+ monkeypatch : pytest .MonkeyPatch ,
1021+ ) -> Callable [[], FastAPIAppServer ]:
1022+ with monkeypatch .context () as patch :
1023+ patch .setenv ("STORAGE_WORKER_MODE" , "true" )
1024+ patch .setenv ("CELERY_POOL" , "threads" )
1025+
1026+ # Create settings with worker mode enabled
1027+ worker_mode_app_settings = ApplicationSettings .create_from_envs ()
1028+
1029+ def _app_server_factory () -> FastAPIAppServer :
1030+ tracing_config = TracingConfig .create (
1031+ tracing_settings = None , # disable tracing in tests
1032+ service_name = "storage-api" ,
1033+ )
1034+ return FastAPIAppServer (
1035+ app = create_app (worker_mode_app_settings , tracing_config )
1036+ )
1037+
1038+ return _app_server_factory
10141039
10151040
10161041@pytest .fixture
10171042async def with_storage_celery_worker (
10181043 celery_app : Celery ,
1019- storage_worker_mode : None ,
1020- app_settings : ApplicationSettings ,
1044+ app_server_factory_with_worker_mode : Callable [[], FastAPIAppServer ],
10211045 register_test_tasks : Callable [[Celery ], None ],
10221046) -> AsyncIterator [TestWorkController ]:
10231047
1024- tracing_config = TracingConfig .create (
1025- tracing_settings = None , # disable tracing in tests
1026- service_name = "storage-api" ,
1027- )
1028-
1029- def _app_server_factory () -> FastAPIAppServer :
1030- return FastAPIAppServer (app = create_app (app_settings , tracing_config ))
1031-
10321048 # NOTE: explicitly connect the signals in tests
10331049 worker_init .connect (
1034- _worker_init_wrapper (celery_app , _app_server_factory ), weak = False
1050+ _worker_init_wrapper (celery_app , app_server_factory_with_worker_mode ),
1051+ weak = False ,
10351052 )
10361053 worker_shutdown .connect (_worker_shutdown_wrapper (celery_app ), weak = False )
10371054
0 commit comments