@@ -44,11 +44,18 @@ async def startup(state: TaskiqState) -> None:
4444
4545 if inspect .iscoroutine (local_app ):
4646 local_app = await local_app
47-
4847 if not isinstance (local_app , web .Application ):
4948 raise ValueError (f"{ app_path } is not an AioHTTP application." )
5049
51- handler = RequestHandler (local_app ._make_handler (), loop = loop )
50+ # Starting the application.
51+ app_runner = web .AppRunner (local_app )
52+ await app_runner .setup ()
53+
54+ if app_runner .server is None :
55+ raise ValueError ("Cannot construct aiohttp app to mock requests" )
56+
57+ # Creating mocked request
58+ handler = RequestHandler (app_runner .server , loop = loop )
5259 handler .transport = asyncio .Transport ()
5360 request = web .Request (
5461 RawRequestMessage (
@@ -88,9 +95,8 @@ async def startup(state: TaskiqState) -> None:
8895 },
8996 )
9097
91- state .aiohttp_app = local_app
98+ state .aiohttp_runner = app_runner
9299 local_app .router ._resources = []
93- await local_app .startup ()
94100
95101 return startup
96102
@@ -104,8 +110,8 @@ async def shutdown(state: TaskiqState) -> None:
104110
105111 :param state: current state.
106112 """
107- await state .aiohttp_app .shutdown ()
108- await state .aiohttp_app .cleanup ()
113+ await state .aiohttp_runner .shutdown ()
114+ await state .aiohttp_runner .cleanup ()
109115
110116
111117def init (broker : AsyncBroker , app_path : str ) -> None :
0 commit comments