Skip to content

Commit 76ec548

Browse files
committed
New test passing plugin names to core
1 parent 8f3ea32 commit 76ec548

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

temporalio/bridge/sdk-core

temporalio/bridge/src/runtime.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ pub fn init_runtime(options: RuntimeOptions) -> PyResult<RuntimeRef> {
124124

125125
// Build metric config, but actual metrics instance is late-bound after
126126
// CoreRuntime is created since it needs Tokio runtime
127-
let mut metrics_conf = metrics;
128-
if let Some(metrics_conf_ref) = metrics_conf.as_ref() {
129-
telemetry_build.attach_service_name(metrics_conf_ref.attach_service_name);
130-
if let Some(prefix) = &metrics_conf_ref.metric_prefix {
127+
if let Some(metrics_conf) = metrics.as_ref() {
128+
telemetry_build.attach_service_name(metrics_conf.attach_service_name);
129+
if let Some(prefix) = &metrics_conf.metric_prefix {
131130
telemetry_build.metric_prefix(prefix.to_string());
132131
}
133132
}
@@ -156,7 +155,7 @@ pub fn init_runtime(options: RuntimeOptions) -> PyResult<RuntimeRef> {
156155
// We late-bind the metrics after core runtime is created since it needs
157156
// the Tokio handle
158157
let mut metrics_call_buffer: Option<Arc<MetricsCallBuffer<BufferedMetricRef>>> = None;
159-
if let Some(metrics_conf) = metrics_conf.take() {
158+
if let Some(metrics_conf) = metrics {
160159
let _guard = core.tokio_handle().enter();
161160
// If they want buffered, cannot have Prom/OTel and we make buffered
162161
if metrics_conf.buffered_with_size > 0 {

temporalio/bridge/src/worker.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,12 @@ impl WorkerRef {
647647
Ok(())
648648
}
649649

650-
fn replace_client(&self, client: &client::ClientRef) {
650+
fn replace_client(&self, client: &client::ClientRef) -> PyResult<()> {
651651
self.worker
652652
.as_ref()
653653
.expect("missing worker")
654-
.replace_client(client.retry_client.clone().into_inner());
654+
.replace_client(client.retry_client.clone().into_inner())
655+
.map_err(|err| PyValueError::new_err(format!("Failed replacing client: {err}")))
655656
}
656657

657658
fn initiate_shutdown(&self) -> PyResult<()> {

temporalio/worker/_worker.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,6 @@ def _init_from_config(self, client: temporalio.client.Client, config: WorkerConf
395395
"""
396396
self._config = config
397397

398-
config.setdefault("skip_client_worker_set_check", False)
399-
400398
if not (
401399
config["activities"]
402400
or config["nexus_service_handlers"]

tests/test_plugins.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import temporalio.client
1010
import temporalio.converter
1111
import temporalio.worker
12+
import temporalio.bridge.temporal_sdk_bridge
1213
from temporalio import workflow
1314
from temporalio.client import Client, ClientConfig, OutboundInterceptor, WorkflowHistory
1415
from temporalio.contrib.pydantic import pydantic_data_converter
@@ -173,6 +174,35 @@ async def test_worker_plugin_basic_config(client: Client) -> None:
173174
]
174175

175176

177+
async def test_worker_plugin_names_forwarded_to_core(
178+
client: Client, monkeypatch: pytest.MonkeyPatch
179+
) -> None:
180+
captured_plugins: list[str] = []
181+
182+
original_new_worker = temporalio.bridge.temporal_sdk_bridge.new_worker
183+
184+
def new_worker_wrapper(runtime_ref, client_ref, config):
185+
nonlocal captured_plugins
186+
captured_plugins = list(config.plugins)
187+
return original_new_worker(runtime_ref, client_ref, config)
188+
189+
monkeypatch.setattr(
190+
temporalio.bridge.temporal_sdk_bridge,
191+
"new_worker",
192+
new_worker_wrapper,
193+
)
194+
195+
plugin1 = SimplePlugin("test-worker-plugin1")
196+
plugin2 = SimplePlugin("test-worker-plugin2")
197+
worker = Worker(
198+
client,
199+
task_queue="queue",
200+
activities=[never_run_activity],
201+
plugins=[plugin1, plugin2],
202+
)
203+
assert captured_plugins == [plugin1.name(), plugin2.name()]
204+
205+
176206
async def test_worker_duplicated_plugin(client: Client) -> None:
177207
new_config = client.config()
178208
new_config["plugins"] = [MyCombinedPlugin()]

tests/worker/test_activity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,6 @@ async def _execute_workflow_with_activity(
13751375
worker_config["activities"] = [fn] + additional_activities
13761376
worker_config["shared_state_manager"] = _default_shared_state_manager
13771377
worker_config["skip_client_worker_set_check"] = True
1378-
print("worker_config[skip_client_worker_set_check] = True\n")
13791378
if not worker_config.get("max_concurrent_activities"):
13801379
worker_config["max_concurrent_activities"] = default_max_concurrent_activities
13811380
async with Worker(**worker_config):

0 commit comments

Comments
 (0)