async def test_delete_many_memcached_metric(self, metrics_registry): driver = MemcachedDriver() driver._client = AsyncMock() await driver.delete_all(["foo", "bar"]) assert ( metrics_registry.get_sample_value( "guillotina_cache_memcached_ops_total", {"type": "delete_many", "error": "none"} ) == 1.0 ) assert ( metrics_registry.get_sample_value( "guillotina_cache_memcached_ops_processing_time_seconds_sum", {"type": "delete_many"} ) > 0 ) assert ( metrics_registry.get_sample_value( "guillotina_cache_memcached_ops_total", {"type": "delete", "error": "none"} ) == 2.0 ) assert ( metrics_registry.get_sample_value( "guillotina_cache_memcached_ops_processing_time_seconds_sum", {"type": "delete"} ) > 0 ) assert metrics_registry.get_sample_value("guillotina_cache_memcached_delete_all_num_keys_sum") > 0
async def test_delete_all_empty_keys(): with mock.patch( "guillotina.contrib.memcached.driver.watch") as watch_mocked: with mock.patch( "guillotina.contrib.memcached.driver.MEMCACHED_OPS_DELETE_ALL_NUM_KEYS" ) as all_keys: driver = MemcachedDriver() driver._client = mock.Mock() await driver.delete_all([]) all_keys.observe.assert_not_called() watch_mocked.assert_not_called()
async def test_delete_all(): with mock.patch( "guillotina.contrib.memcached.driver.watch") as watch_mocked: with mock.patch( "guillotina.contrib.memcached.driver.MEMCACHED_OPS_DELETE_ALL_NUM_KEYS" ) as all_keys: driver = MemcachedDriver() driver._client = mock.Mock() await driver.delete_all(["foo", "bar"]) watch_mocked.assert_called() all_keys.observe.assert_called_with(2) driver._client.delete.assert_has_calls([ mock.call(safe_key("foo"), noreply=True), mock.call(safe_key("bar"), noreply=True) ])
async def test_get_memcached_metric(self, metrics_registry): driver = MemcachedDriver() driver._client = AsyncMock() await driver.get("foo") assert ( metrics_registry.get_sample_value( "guillotina_cache_memcached_ops_total", {"type": "get", "error": "none"} ) == 1.0 ) assert ( metrics_registry.get_sample_value( "guillotina_cache_memcached_ops_processing_time_seconds_sum", {"type": "get"} ) > 0 )
async def test_connect_metric(self, metrics_registry, event_loop): driver = MemcachedDriver() driver._client = AsyncMock() await driver.initialize(event_loop) assert ( metrics_registry.get_sample_value( "guillotina_cache_memcached_ops_total", {"type": "connect", "error": "none"} ) == 1.0 ) assert ( metrics_registry.get_sample_value( "guillotina_cache_memcached_ops_processing_time_seconds_sum", {"type": "connect"} ) > 0 )