X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/650265966e83fca4ce8e9a416e9b5e358e82be98..1913b4edcb176909e8cf7ef3272c41bf8f2c7e1a:/sdk/python/tests/test_keep_client.py diff --git a/sdk/python/tests/test_keep_client.py b/sdk/python/tests/test_keep_client.py index 5a7cf2c2a4..0fe3961136 100644 --- a/sdk/python/tests/test_keep_client.py +++ b/sdk/python/tests/test_keep_client.py @@ -12,6 +12,7 @@ from builtins import object import hashlib import mock import os +import errno import pycurl import random import re @@ -1707,3 +1708,49 @@ class KeepDiskCacheTestCase(unittest.TestCase, tutil.ApiClientMock): with self.assertRaises(arvados.errors.KeepCacheError): with tutil.mock_keep_responses(self.data, 200) as mock: keep_client.get(self.locator) + + + @mock.patch('mmap.mmap') + def test_disk_cache_retry_write_error(self, mockmmap): + block_cache = arvados.keep.KeepBlockCache(disk_cache=True, + disk_cache_dir=self.disk_cache_dir) + + keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=block_cache) + + mockmmap.side_effect = (OSError(errno.ENOSPC, "no space"), self.data) + + cache_max_before = block_cache.cache_max + + with tutil.mock_keep_responses(self.data, 200) as mock: + self.assertTrue(tutil.binary_compare(keep_client.get(self.locator), self.data)) + + self.assertIsNotNone(keep_client.get_from_cache(self.locator)) + + with open(os.path.join(self.disk_cache_dir, self.locator[0:3], self.locator+".keepcacheblock"), "rb") as f: + self.assertTrue(tutil.binary_compare(f.read(), self.data)) + + # shrank the cache in response to ENOSPC + self.assertTrue(cache_max_before > block_cache.cache_max) + + + @mock.patch('mmap.mmap') + def test_disk_cache_retry_write_error2(self, mockmmap): + block_cache = arvados.keep.KeepBlockCache(disk_cache=True, + disk_cache_dir=self.disk_cache_dir) + + keep_client = arvados.KeepClient(api_client=self.api_client, block_cache=block_cache) + + mockmmap.side_effect = (OSError(errno.ENOMEM, "no memory"), self.data) + + slots_before = block_cache._max_slots + + with tutil.mock_keep_responses(self.data, 200) as mock: + self.assertTrue(tutil.binary_compare(keep_client.get(self.locator), self.data)) + + self.assertIsNotNone(keep_client.get_from_cache(self.locator)) + + with open(os.path.join(self.disk_cache_dir, self.locator[0:3], self.locator+".keepcacheblock"), "rb") as f: + self.assertTrue(tutil.binary_compare(f.read(), self.data)) + + # shrank the cache in response to ENOMEM + self.assertTrue(slots_before > block_cache._max_slots)