@@ -204,6 +204,8 @@ def test_throttles_service_with_volume_above_median_multiple(
204204
205205 def test_single_service_contributing_100_pct (self , notify_api : "Flask" , mocker : MockerFixture ) -> None :
206206 mocker .patch ("app.load_shedding.is_worker_overloaded" , return_value = True )
207+ notify_api .config ["THROTTLE_CONTRIBUTION_MIN_SERVICES" ] = 1
208+ notify_api .config ["THROTTLE_CONTRIBUTION_MIN_VOLUME" ] = 1
207209
208210 # Test with single service (contributes 100% of load)
209211 # Should be throttled by contribution % (100% > 20% threshold)
@@ -216,6 +218,38 @@ def test_single_service_contributing_100_pct(self, notify_api: "Flask", mocker:
216218 # Single service contributing 100% should be throttled (exceeds 20% threshold)
217219 assert should_throttle_service ("single" ) is True
218220
221+ def test_does_not_throttle_by_contribution_with_few_services (
222+ self , notify_api : "Flask" , mocker : MockerFixture
223+ ) -> None :
224+ mocker .patch ("app.load_shedding.is_worker_overloaded" , return_value = True )
225+ notify_api .config ["THROTTLE_CONTRIBUTION_MIN_SERVICES" ] = 5
226+ notify_api .config ["THROTTLE_CONTRIBUTION_MIN_VOLUME" ] = 50
227+
228+ # Only 2 services, high contribution but below min service count
229+ service_volumes = {"big" : 9 , "small" : 1 }
230+
231+ mock_tracker = mocker .patch ("app.load_shedding._volume_tracker" )
232+ mock_tracker .get_volumes .return_value = service_volumes
233+
234+ # Should not throttle by contribution; median multiple also not met
235+ assert should_throttle_service ("big" ) is False
236+
237+ def test_does_not_throttle_by_contribution_with_low_total_volume (
238+ self , notify_api : "Flask" , mocker : MockerFixture
239+ ) -> None :
240+ mocker .patch ("app.load_shedding.is_worker_overloaded" , return_value = True )
241+ notify_api .config ["THROTTLE_CONTRIBUTION_MIN_SERVICES" ] = 3
242+ notify_api .config ["THROTTLE_CONTRIBUTION_MIN_VOLUME" ] = 50
243+
244+ # 3 services but total volume below min threshold
245+ service_volumes = {"big" : 8 , "mid" : 1 , "small" : 1 }
246+
247+ mock_tracker = mocker .patch ("app.load_shedding._volume_tracker" )
248+ mock_tracker .get_volumes .return_value = service_volumes
249+
250+ # Should not throttle by contribution; median multiple also not met
251+ assert should_throttle_service ("big" ) is False
252+
219253 def test_returns_false_on_error (self , notify_api : "Flask" , mocker : MockerFixture ) -> None :
220254 mocker .patch ("app.load_shedding.is_worker_overloaded" , return_value = True )
221255
0 commit comments