44import samples .greeter_pb2 as greeter_pb2
55
66
7- async def test_grpc_cc_enabled (grpc_client , service_client , testpoint ):
7+ async def test_grpc_congestion_control_limit (grpc_client , service_client , testpoint ):
8+ @testpoint ('congestion-control-sensor' )
9+ def tp_congestion_control_sensor (data ):
10+ return {}
11+
812 @testpoint ('congestion-control' )
9- def tp_cc_enable (data ):
13+ def tp_congestion_control (data ):
1014 return {'force-rps-limit' : 0 }
1115
1216 @testpoint ('congestion-control-apply' )
13- def tp_cc_apply (data ):
17+ def tp_congestion_control_apply (data ):
1418 return {}
1519
1620 # wait until server obtains the new limit, up to 1 second
1721 await service_client .enable_testpoints ()
18- await tp_cc_enable .wait_call ()
19- await tp_cc_apply .wait_call ()
22+ await tp_congestion_control .wait_call ()
2023
2124 # Random non-ping handler is throttled
2225 with pytest .raises (grpc .RpcError ) as error :
@@ -27,11 +30,65 @@ def tp_cc_apply(data):
2730
2831 # A hack to disable CC for other tests
2932 @testpoint ('congestion-control' )
30- def tp_cc_disable (data ):
33+ def tp_congestion_control_disable (data ):
34+ return {'force-rps-limit' : None }
35+
36+ await tp_congestion_control_disable .wait_call ()
37+
38+
39+ async def test_grpc_congestion_control_activate (grpc_client , service_client , testpoint ):
40+ @testpoint ('congestion-control-sensor' )
41+ def tp_congestion_control_sensor (data ):
42+ return {
43+ 'current-load' : 100 ,
44+ 'overload-events-count' : 4 ,
45+ 'no-overload-events-count' : 96 ,
46+ }
47+
48+ @testpoint ('congestion-control' )
49+ def tp_congestion_control (data ):
50+ return {}
51+
52+ @testpoint ('congestion-control-apply' )
53+ def tp_congestion_control_apply (data ):
3154 return {}
3255
33- await tp_cc_disable .wait_call ()
34- await tp_cc_apply .wait_call ()
56+ # is_overloaded -> true
57+ await service_client .enable_testpoints ()
58+ await tp_congestion_control_sensor .wait_call ()
59+ await tp_congestion_control .wait_call ()
60+
61+ # current_limit -> 1
62+ await tp_congestion_control_sensor .wait_call ()
63+ await tp_congestion_control .wait_call ()
64+
65+ with pytest .raises (grpc .RpcError ) as error :
66+ for i in range (0 , 2 ):
67+ request = greeter_pb2 .GreetingRequest (name = f'Name0{ i } /1' )
68+ await grpc_client .SayHello (request , wait_for_ready = True )
69+ assert error .value .details () == 'Congestion control: rate limit exceeded'
70+ assert error .value .code () == grpc .StatusCode .RESOURCE_EXHAUSTED
71+
72+ @testpoint ('congestion-control-sensor' )
73+ def tp_congestion_control_sensor_disable (data ):
74+ return {
75+ 'current-load' : 100 ,
76+ 'overload-events-count' : 0 ,
77+ 'no-overload-events-count' : 100 ,
78+ }
79+
80+ # current_limit -> 1
81+ await tp_congestion_control_sensor_disable .wait_call ()
82+ await tp_congestion_control .wait_call ()
83+
84+ # current_limit -> null
85+ await tp_congestion_control_sensor_disable .wait_call ()
86+ await tp_congestion_control .wait_call ()
87+
88+ for i in range (1 , 10 ):
89+ request = greeter_pb2 .GreetingRequest (name = f'Name{ i } /2' )
90+ response = await grpc_client .SayHello (request , wait_for_ready = True )
91+ assert response .greeting == f'Hello, Name{ i } /2!'
3592
3693
3794async def test_grpc_cancellation (grpc_client , service_client , testpoint ):
0 commit comments