@@ -95,37 +95,47 @@ def pg_dispatcher() -> DispatcherMain:
95
95
def test_settings ():
96
96
return DispatcherSettings (BASIC_CONFIG )
97
97
98
+
99
+ @pytest .fixture
100
+ def adispatcher_factory ():
101
+ @contextlib .asynccontextmanager
102
+ async def _rf (config ):
103
+ dispatcher = None
104
+ try :
105
+ settings = DispatcherSettings (config )
106
+ dispatcher = from_settings (settings = settings )
107
+
108
+ await dispatcher .connect_signals ()
109
+ await dispatcher .start_working ()
110
+ await dispatcher .wait_for_producers_ready ()
111
+ await dispatcher .pool .events .workers_ready .wait ()
112
+
113
+ assert dispatcher .pool .finished_count == 0 # sanity
114
+ assert dispatcher .control_count == 0
115
+
116
+ yield dispatcher
117
+ finally :
118
+ if dispatcher :
119
+ try :
120
+ await dispatcher .shutdown ()
121
+ await dispatcher .cancel_tasks ()
122
+ except Exception :
123
+ logger .exception ('shutdown had error' )
124
+ return _rf
125
+
126
+
98
127
@pytest_asyncio .fixture (
99
128
loop_scope = "function" ,
100
129
scope = "function" ,
101
130
params = ['ProcessManager' , 'ForkServerManager' ],
102
131
ids = ["fork" , "forkserver" ],
103
132
)
104
- async def apg_dispatcher (request ) -> AsyncIterator [DispatcherMain ]:
105
- dispatcher = None
106
- try :
107
- this_test_config = BASIC_CONFIG .copy ()
108
- this_test_config .setdefault ('service' , {})
109
- this_test_config ['service' ]['process_manager_cls' ] = request .param
110
- this_settings = DispatcherSettings (this_test_config )
111
- dispatcher = from_settings (settings = this_settings )
112
-
113
- await dispatcher .connect_signals ()
114
- await dispatcher .start_working ()
115
- await dispatcher .wait_for_producers_ready ()
116
- await dispatcher .pool .events .workers_ready .wait ()
117
-
118
- assert dispatcher .pool .finished_count == 0 # sanity
119
- assert dispatcher .control_count == 0
120
-
133
+ async def apg_dispatcher (request , adispatcher_factory ) -> AsyncIterator [DispatcherMain ]:
134
+ this_test_config = BASIC_CONFIG .copy ()
135
+ this_test_config .setdefault ('service' , {})
136
+ this_test_config ['service' ]['process_manager_cls' ] = request .param
137
+ async with adispatcher_factory (this_test_config ) as dispatcher :
121
138
yield dispatcher
122
- finally :
123
- if dispatcher :
124
- try :
125
- await dispatcher .shutdown ()
126
- await dispatcher .cancel_tasks ()
127
- except Exception :
128
- logger .exception ('shutdown had error' )
129
139
130
140
131
141
@pytest_asyncio .fixture (loop_scope = "function" , scope = "function" )
0 commit comments