22import grpc
33import pytest
44from datetime import datetime , timezone
5- from unittest .mock import ANY , AsyncMock , MagicMock , patch
5+ from unittest .mock import ANY , AsyncMock , MagicMock , call , patch
66
77from 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