def test_threshold_hit_prevents_consequent_calls(mock_remote: Mock): mock_remote.side_effect = ConnectionError('Connection refused') circuitbreaker = CircuitBreakerMonitor.get('threshold_1') assert circuitbreaker.closed with raises(ConnectionError): circuit_threshold_1() assert circuitbreaker.opened with raises(CircuitBreakerError): circuit_threshold_1() mock_remote.assert_called_once()
def test_jumpstart_models_cache_set_reset_fxs(mock_model_cache: Mock): # test change of region resets cache accessors.JumpStartModelsAccessor.get_model_header( region="us-west-2", model_id="pytorch-ic-mobilenet-v2", version="*") accessors.JumpStartModelsAccessor.get_model_specs( region="us-west-2", model_id="pytorch-ic-mobilenet-v2", version="*") mock_model_cache.assert_called_once() mock_model_cache.reset_mock() accessors.JumpStartModelsAccessor.get_model_header( region="us-east-2", model_id="pytorch-ic-mobilenet-v2", version="*") mock_model_cache.assert_called_once() mock_model_cache.reset_mock() accessors.JumpStartModelsAccessor.get_model_specs( region="us-west-1", model_id="pytorch-ic-mobilenet-v2", version="*") mock_model_cache.assert_called_once() mock_model_cache.reset_mock() # test set_cache_kwargs accessors.JumpStartModelsAccessor.set_cache_kwargs( cache_kwargs={"some": "kwarg"}) mock_model_cache.assert_called_once_with(some="kwarg") mock_model_cache.reset_mock() accessors.JumpStartModelsAccessor.set_cache_kwargs( region="us-west-2", cache_kwargs={"some": "kwarg"}) mock_model_cache.assert_called_once_with(region="us-west-2", some="kwarg") mock_model_cache.reset_mock() # test reset cache accessors.JumpStartModelsAccessor.reset_cache( cache_kwargs={"some": "kwarg"}) mock_model_cache.assert_called_once_with(some="kwarg") mock_model_cache.reset_mock() accessors.JumpStartModelsAccessor.reset_cache( region="us-west-2", cache_kwargs={"some": "kwarg"}) mock_model_cache.assert_called_once_with(region="us-west-2", some="kwarg") mock_model_cache.reset_mock() accessors.JumpStartModelsAccessor.reset_cache() mock_model_cache.assert_called_once_with() mock_model_cache.reset_mock() # validate region and cache kwargs utility assert { "some": "kwarg" } == accessors.JumpStartModelsAccessor._validate_and_mutate_region_cache_kwargs( {"some": "kwarg"}, "us-west-2") assert { "some": "kwarg" } == accessors.JumpStartModelsAccessor._validate_and_mutate_region_cache_kwargs( { "some": "kwarg", "region": "us-west-2" }, "us-west-2") with pytest.raises(ValueError): accessors.JumpStartModelsAccessor._validate_and_mutate_region_cache_kwargs( { "some": "kwarg", "region": "us-east-2" }, "us-west-2") # necessary because accessors is a static module reload(accessors)