File tree Expand file tree Collapse file tree 2 files changed +39
-30
lines changed
Expand file tree Collapse file tree 2 files changed +39
-30
lines changed Original file line number Diff line number Diff line change 1+ from collections import Counter
2+
3+ import pytest
4+
5+ import temporalio .bridge .temporal_sdk_bridge
6+ from temporalio .client import Client
7+ from temporalio .plugin import SimplePlugin
8+ from temporalio .worker import Worker
9+ from tests .worker .test_worker import never_run_activity
10+
11+
12+ async def test_worker_plugin_names_forwarded_to_core (
13+ client : Client , monkeypatch : pytest .MonkeyPatch
14+ ) -> None :
15+ captured_plugins : list [str ] = []
16+
17+ original_new_worker = temporalio .bridge .temporal_sdk_bridge .new_worker
18+
19+ def new_worker_wrapper (runtime_ref , client_ref , config ):
20+ nonlocal captured_plugins
21+ captured_plugins = list (config .plugins )
22+ return original_new_worker (runtime_ref , client_ref , config )
23+
24+ monkeypatch .setattr (
25+ temporalio .bridge .temporal_sdk_bridge ,
26+ "new_worker" ,
27+ new_worker_wrapper ,
28+ )
29+
30+ plugin1 = SimplePlugin ("test-worker-plugin1" )
31+ plugin2 = SimplePlugin ("test-worker-plugin2" )
32+ Worker (
33+ client ,
34+ task_queue = "queue" ,
35+ activities = [never_run_activity ],
36+ plugins = [plugin1 , plugin2 ],
37+ )
38+ # Use counter to compare unordered lists
39+ assert Counter (captured_plugins ) == Counter ([plugin1 .name (), plugin2 .name ()])
Original file line number Diff line number Diff line change 66
77import pytest
88
9- import temporalio .bridge .temporal_sdk_bridge
109import temporalio .client
1110import temporalio .converter
1211import temporalio .worker
@@ -178,35 +177,6 @@ async def test_worker_plugin_basic_config(client: Client) -> None:
178177 ]
179178
180179
181- async def test_worker_plugin_names_forwarded_to_core (
182- client : Client , monkeypatch : pytest .MonkeyPatch
183- ) -> None :
184- captured_plugins : list [str ] = []
185-
186- original_new_worker = temporalio .bridge .temporal_sdk_bridge .new_worker
187-
188- def new_worker_wrapper (runtime_ref , client_ref , config ):
189- nonlocal captured_plugins
190- captured_plugins = list (config .plugins )
191- return original_new_worker (runtime_ref , client_ref , config )
192-
193- monkeypatch .setattr (
194- temporalio .bridge .temporal_sdk_bridge ,
195- "new_worker" ,
196- new_worker_wrapper ,
197- )
198-
199- plugin1 = SimplePlugin ("test-worker-plugin1" )
200- plugin2 = SimplePlugin ("test-worker-plugin2" )
201- worker = Worker (
202- client ,
203- task_queue = "queue" ,
204- activities = [never_run_activity ],
205- plugins = [plugin1 , plugin2 ],
206- )
207- assert captured_plugins == [plugin1 .name (), plugin2 .name ()]
208-
209-
210180async def test_worker_duplicated_plugin (client : Client ) -> None :
211181 new_config = client .config ()
212182 new_config ["plugins" ] = [MyCombinedPlugin ()]
You can’t perform that action at this time.
0 commit comments