Skip to content

Commit 937231d

Browse files
Bernd VerstCopilot
andcommitted
Add sync client recreation input test
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d89bc10 commit 937231d

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

tests/durabletask/test_client.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import grpc
33
import pytest
44
from datetime import datetime, timezone
5-
from unittest.mock import ANY, AsyncMock, MagicMock, patch
5+
from unittest.mock import ANY, AsyncMock, MagicMock, call, patch
66

77
from google.protobuf import wrappers_pb2
88

@@ -327,23 +327,32 @@ def test_client_stores_resiliency_options_for_recreation():
327327
assert client._interceptors == interceptors
328328

329329

330-
def test_sync_client_recreates_sdk_owned_channel_after_repeated_unavailable():
330+
def test_sync_client_recreates_sdk_owned_channel_with_original_transport_inputs():
331331
first_channel = MagicMock(name="first-channel")
332332
second_channel = MagicMock(name="second-channel")
333333
first_stub = MagicMock()
334334
second_stub = MagicMock()
335335
second_stub.GetInstance.return_value = MagicMock(exists=False)
336+
host_address = "localhost:4001"
337+
interceptors = [DefaultClientInterceptorImpl(METADATA)]
338+
channel_options = GrpcChannelOptions(max_receive_message_length=1234)
336339

337340
rpc_error = FakeRpcError(grpc.StatusCode.UNAVAILABLE)
338341
first_stub.GetInstance.side_effect = rpc_error
339342

340343
timer = MagicMock()
341344

342-
with patch("durabletask.client.shared.get_grpc_channel", side_effect=[first_channel, second_channel]), patch(
345+
with patch(
346+
"durabletask.client.shared.get_grpc_channel",
347+
side_effect=[first_channel, second_channel],
348+
) as mock_get_channel, patch(
343349
"durabletask.client.stubs.TaskHubSidecarServiceStub", side_effect=[first_stub, second_stub]
344350
), patch("threading.Timer", return_value=timer) as mock_timer:
345351
client = TaskHubGrpcClient(
346-
host_address="localhost:4001",
352+
host_address=host_address,
353+
secure_channel=True,
354+
interceptors=interceptors,
355+
channel_options=channel_options,
347356
resiliency_options=GrpcClientResiliencyOptions(
348357
channel_recreate_failure_threshold=1,
349358
min_recreate_interval_seconds=0.0,
@@ -353,6 +362,16 @@ def test_sync_client_recreates_sdk_owned_channel_after_repeated_unavailable():
353362
client.get_orchestration_state("abc")
354363
client.get_orchestration_state("abc")
355364

365+
expected_channel_call = call(
366+
host_address=host_address,
367+
secure_channel=True,
368+
interceptors=interceptors,
369+
channel_options=channel_options,
370+
)
371+
assert mock_get_channel.call_args_list == [
372+
expected_channel_call,
373+
expected_channel_call,
374+
]
356375
assert client._channel is second_channel
357376
mock_timer.assert_called_once_with(30.0, first_channel.close)
358377
assert timer.daemon is True

0 commit comments

Comments
 (0)