1- from unittest .mock import ANY , patch
1+ from unittest .mock import patch
22
33from durabletask .internal .grpc_interceptor import DefaultClientInterceptorImpl
44from durabletask .internal .shared import get_default_host_address , get_grpc_channel
1111def test_get_grpc_channel_insecure ():
1212 with patch ("grpc.insecure_channel" ) as mock_channel :
1313 get_grpc_channel (HOST_ADDRESS , False , interceptors = INTERCEPTORS )
14- mock_channel .assert_called_once_with (HOST_ADDRESS )
14+ args , kwargs = mock_channel .call_args
15+ assert args [0 ] == HOST_ADDRESS
16+ assert "options" in kwargs and kwargs ["options" ] is None
1517
1618
1719def test_get_grpc_channel_secure ():
@@ -20,13 +22,18 @@ def test_get_grpc_channel_secure():
2022 patch ("grpc.ssl_channel_credentials" ) as mock_credentials ,
2123 ):
2224 get_grpc_channel (HOST_ADDRESS , True , interceptors = INTERCEPTORS )
23- mock_channel .assert_called_once_with (HOST_ADDRESS , mock_credentials .return_value )
25+ args , kwargs = mock_channel .call_args
26+ assert args [0 ] == HOST_ADDRESS
27+ assert args [1 ] == mock_credentials .return_value
28+ assert "options" in kwargs and kwargs ["options" ] is None
2429
2530
2631def test_get_grpc_channel_default_host_address ():
2732 with patch ("grpc.insecure_channel" ) as mock_channel :
2833 get_grpc_channel (None , False , interceptors = INTERCEPTORS )
29- mock_channel .assert_called_once_with (get_default_host_address ())
34+ args , kwargs = mock_channel .call_args
35+ assert args [0 ] == get_default_host_address ()
36+ assert "options" in kwargs and kwargs ["options" ] is None
3037
3138
3239def test_get_grpc_channel_with_metadata ():
@@ -35,7 +42,9 @@ def test_get_grpc_channel_with_metadata():
3542 patch ("grpc.intercept_channel" ) as mock_intercept_channel ,
3643 ):
3744 get_grpc_channel (HOST_ADDRESS , False , interceptors = INTERCEPTORS )
38- mock_channel .assert_called_once_with (HOST_ADDRESS )
45+ args , kwargs = mock_channel .call_args
46+ assert args [0 ] == HOST_ADDRESS
47+ assert "options" in kwargs and kwargs ["options" ] is None
3948 mock_intercept_channel .assert_called_once ()
4049
4150 # Capture and check the arguments passed to intercept_channel()
@@ -54,40 +63,80 @@ def test_grpc_channel_with_host_name_protocol_stripping():
5463
5564 prefix = "grpc://"
5665 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
57- mock_insecure_channel .assert_called_with (host_name )
66+ args , kwargs = mock_insecure_channel .call_args
67+ assert args [0 ] == host_name
68+ assert "options" in kwargs and kwargs ["options" ] is None
5869
5970 prefix = "http://"
6071 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
61- mock_insecure_channel .assert_called_with (host_name )
72+ args , kwargs = mock_insecure_channel .call_args
73+ assert args [0 ] == host_name
74+ assert "options" in kwargs and kwargs ["options" ] is None
6275
6376 prefix = "HTTP://"
6477 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
65- mock_insecure_channel .assert_called_with (host_name )
78+ args , kwargs = mock_insecure_channel .call_args
79+ assert args [0 ] == host_name
80+ assert "options" in kwargs and kwargs ["options" ] is None
6681
6782 prefix = "GRPC://"
6883 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
69- mock_insecure_channel .assert_called_with (host_name )
84+ args , kwargs = mock_insecure_channel .call_args
85+ assert args [0 ] == host_name
86+ assert "options" in kwargs and kwargs ["options" ] is None
7087
7188 prefix = ""
7289 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
73- mock_insecure_channel .assert_called_with (host_name )
90+ args , kwargs = mock_insecure_channel .call_args
91+ assert args [0 ] == host_name
92+ assert "options" in kwargs and kwargs ["options" ] is None
7493
7594 prefix = "grpcs://"
7695 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
77- mock_secure_channel .assert_called_with (host_name , ANY )
96+ args , kwargs = mock_secure_channel .call_args
97+ assert args [0 ] == host_name
98+ assert "options" in kwargs and kwargs ["options" ] is None
7899
79100 prefix = "https://"
80101 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
81- mock_secure_channel .assert_called_with (host_name , ANY )
102+ args , kwargs = mock_secure_channel .call_args
103+ assert args [0 ] == host_name
104+ assert "options" in kwargs and kwargs ["options" ] is None
82105
83106 prefix = "HTTPS://"
84107 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
85- mock_secure_channel .assert_called_with (host_name , ANY )
108+ args , kwargs = mock_secure_channel .call_args
109+ assert args [0 ] == host_name
110+ assert "options" in kwargs and kwargs ["options" ] is None
86111
87112 prefix = "GRPCS://"
88113 get_grpc_channel (prefix + host_name , interceptors = INTERCEPTORS )
89- mock_secure_channel .assert_called_with (host_name , ANY )
114+ args , kwargs = mock_secure_channel .call_args
115+ assert args [0 ] == host_name
116+ assert "options" in kwargs and kwargs ["options" ] is None
90117
91118 prefix = ""
92119 get_grpc_channel (prefix + host_name , True , interceptors = INTERCEPTORS )
93- mock_secure_channel .assert_called_with (host_name , ANY )
120+ args , kwargs = mock_secure_channel .call_args
121+ assert args [0 ] == host_name
122+ assert "options" in kwargs and kwargs ["options" ] is None
123+
124+
125+ def test_sync_channel_passes_base_options_and_max_lengths ():
126+ base_options = [
127+ ("grpc.max_send_message_length" , 1234 ),
128+ ("grpc.max_receive_message_length" , 5678 ),
129+ ("grpc.primary_user_agent" , "durabletask-tests" ),
130+ ]
131+ with patch ("grpc.insecure_channel" ) as mock_channel :
132+ get_grpc_channel (HOST_ADDRESS , False , options = base_options )
133+ # Ensure called with options kwarg
134+ assert mock_channel .call_count == 1
135+ args , kwargs = mock_channel .call_args
136+ assert args [0 ] == HOST_ADDRESS
137+ assert "options" in kwargs
138+ opts = kwargs ["options" ]
139+ # Check our base options made it through
140+ assert ("grpc.max_send_message_length" , 1234 ) in opts
141+ assert ("grpc.max_receive_message_length" , 5678 ) in opts
142+ assert ("grpc.primary_user_agent" , "durabletask-tests" ) in opts
0 commit comments