55
66from durabletask .aio .internal .shared import get_grpc_aio_channel
77
8- HOST_ADDRESS = ' localhost:50051'
8+ HOST_ADDRESS = " localhost:50051"
99
1010
1111def _find_option (options , key ):
1212 for k , v in options :
1313 if k == key :
1414 return v
15- raise AssertionError (f' Option with key { key } not found in options: { options } ' )
15+ raise AssertionError (f" Option with key { key } not found in options: { options } " )
1616
1717
1818def test_aio_channel_passes_base_options_and_max_lengths ():
1919 base_options = [
20- (' grpc.max_send_message_length' , 4321 ),
21- (' grpc.max_receive_message_length' , 8765 ),
22- (' grpc.primary_user_agent' , ' durabletask-aio-tests' ),
20+ (" grpc.max_send_message_length" , 4321 ),
21+ (" grpc.max_receive_message_length" , 8765 ),
22+ (" grpc.primary_user_agent" , " durabletask-aio-tests" ),
2323 ]
24- with patch (' durabletask.aio.internal.shared.grpc_aio.insecure_channel' ) as mock_channel :
24+ with patch (" durabletask.aio.internal.shared.grpc_aio.insecure_channel" ) as mock_channel :
2525 get_grpc_aio_channel (HOST_ADDRESS , False , options = base_options )
2626 # Ensure called with options kwarg
2727 assert mock_channel .call_count == 1
2828 args , kwargs = mock_channel .call_args
2929 assert args [0 ] == HOST_ADDRESS
30- assert ' options' in kwargs
31- opts = kwargs [' options' ]
30+ assert " options" in kwargs
31+ opts = kwargs [" options" ]
3232 # Check our base options made it through
33- assert (' grpc.max_send_message_length' , 4321 ) in opts
34- assert (' grpc.max_receive_message_length' , 8765 ) in opts
35- assert (' grpc.primary_user_agent' , ' durabletask-aio-tests' ) in opts
33+ assert (" grpc.max_send_message_length" , 4321 ) in opts
34+ assert (" grpc.max_receive_message_length" , 8765 ) in opts
35+ assert (" grpc.primary_user_agent" , " durabletask-aio-tests" ) in opts
3636
3737
3838def test_aio_channel_merges_env_keepalive_and_retry (monkeypatch : pytest .MonkeyPatch ):
@@ -42,53 +42,53 @@ def test_aio_channel_merges_env_keepalive_and_retry(monkeypatch: pytest.MonkeyPa
4242 initial_backoff_ms = 250
4343 max_backoff_ms = 2000
4444 backoff_multiplier = 1.5
45- codes = [' RESOURCE_EXHAUSTED' ]
45+ codes = [" RESOURCE_EXHAUSTED" ]
4646 service_config = {
47- ' methodConfig' : [
47+ " methodConfig" : [
4848 {
49- ' name' : [{' service' : '' }], # match all services/methods
50- ' retryPolicy' : {
51- ' maxAttempts' : max_attempts ,
52- ' initialBackoff' : f' { initial_backoff_ms / 1000.0 } s' ,
53- ' maxBackoff' : f' { max_backoff_ms / 1000.0 } s' ,
54- ' backoffMultiplier' : backoff_multiplier ,
55- ' retryableStatusCodes' : codes ,
49+ " name" : [{" service" : "" }], # match all services/methods
50+ " retryPolicy" : {
51+ " maxAttempts" : max_attempts ,
52+ " initialBackoff" : f" { initial_backoff_ms / 1000.0 } s" ,
53+ " maxBackoff" : f" { max_backoff_ms / 1000.0 } s" ,
54+ " backoffMultiplier" : backoff_multiplier ,
55+ " retryableStatusCodes" : codes ,
5656 },
5757 }
5858 ]
5959 }
6060
61- base_options = [(' grpc.service_config' , json .dumps (service_config ))]
61+ base_options = [(" grpc.service_config" , json .dumps (service_config ))]
6262
63- with patch (' durabletask.aio.internal.shared.grpc_aio.insecure_channel' ) as mock_channel :
63+ with patch (" durabletask.aio.internal.shared.grpc_aio.insecure_channel" ) as mock_channel :
6464 get_grpc_aio_channel (HOST_ADDRESS , False , options = base_options )
6565
6666 args , kwargs = mock_channel .call_args
6767 assert args [0 ] == HOST_ADDRESS
68- assert ' options' in kwargs
69- opts = kwargs [' options' ]
68+ assert " options" in kwargs
69+ opts = kwargs [" options" ]
7070
7171 # Retry service config present and parses correctly
72- svc_cfg_str = _find_option (opts , ' grpc.service_config' )
72+ svc_cfg_str = _find_option (opts , " grpc.service_config" )
7373 svc_cfg = json .loads (svc_cfg_str )
74- assert ' methodConfig' in svc_cfg and isinstance (svc_cfg [' methodConfig' ], list )
75- retry_policy = svc_cfg [' methodConfig' ][0 ][' retryPolicy' ]
76- assert retry_policy [' maxAttempts' ] == 4
77- assert retry_policy [' initialBackoff' ] == f' { 250 / 1000.0 } s'
78- assert retry_policy [' maxBackoff' ] == f' { 2000 / 1000.0 } s'
79- assert retry_policy [' backoffMultiplier' ] == 1.5
74+ assert " methodConfig" in svc_cfg and isinstance (svc_cfg [" methodConfig" ], list )
75+ retry_policy = svc_cfg [" methodConfig" ][0 ][" retryPolicy" ]
76+ assert retry_policy [" maxAttempts" ] == 4
77+ assert retry_policy [" initialBackoff" ] == f" { 250 / 1000.0 } s"
78+ assert retry_policy [" maxBackoff" ] == f" { 2000 / 1000.0 } s"
79+ assert retry_policy [" backoffMultiplier" ] == 1.5
8080 # Codes are upper-cased list
81- assert ' RESOURCE_EXHAUSTED' in retry_policy [' retryableStatusCodes' ]
81+ assert " RESOURCE_EXHAUSTED" in retry_policy [" retryableStatusCodes" ]
8282
8383
8484def test_aio_secure_channel_receives_options_when_secure_true ():
85- base_options = [(' grpc.max_receive_message_length' , 999999 )]
85+ base_options = [(" grpc.max_receive_message_length" , 999999 )]
8686 with (
87- patch (' durabletask.aio.internal.shared.grpc_aio.secure_channel' ) as mock_channel ,
88- patch (' grpc.ssl_channel_credentials' ) as mock_credentials ,
87+ patch (" durabletask.aio.internal.shared.grpc_aio.secure_channel" ) as mock_channel ,
88+ patch (" grpc.ssl_channel_credentials" ) as mock_credentials ,
8989 ):
9090 get_grpc_aio_channel (HOST_ADDRESS , True , options = base_options )
9191 args , kwargs = mock_channel .call_args
9292 assert args [0 ] == HOST_ADDRESS
9393 assert args [1 ] == mock_credentials .return_value
94- assert (' grpc.max_receive_message_length' , 999999 ) in kwargs .get (' options' , [])
94+ assert (" grpc.max_receive_message_length" , 999999 ) in kwargs .get (" options" , [])
0 commit comments