1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 from __future__ import absolute_import
6 from future import standard_library
7 standard_library.install_aliases()
9 import arvados_fuse.command
15 from . import run_test_server
19 from .integration_test import IntegrationTest
22 class KeepClientRetry(unittest.TestCase):
23 origKeepClient = arvados.keep.KeepClient
26 self.mnt = tempfile.mkdtemp()
27 run_test_server.authorize_with('active')
32 @mock.patch('arvados_fuse.arvados.keep.KeepClient')
33 def _test_retry(self, num_retries, argv, kc):
34 kc.side_effect = lambda *args, **kw: self.origKeepClient(*args, **kw)
35 with arvados_fuse.command.Mount(
36 arvados_fuse.command.ArgumentParser().parse_args(
39 self.assertEqual(num_retries, kc.call_args[1].get('num_retries'))
41 def test_default_retry_10(self):
42 self._test_retry(10, [])
44 def test_retry_2(self):
45 self._test_retry(2, ['--retries=2'])
47 def test_no_retry(self):
48 self._test_retry(0, ['--retries=0'])
50 class RetryPUT(IntegrationTest):
51 @mock.patch('time.sleep')
52 @IntegrationTest.mount(argv=['--read-write', '--mount-tmp=zzz'])
53 def test_retry_write(self, sleep):
54 mockedCurl = mock.Mock(spec=pycurl.Curl(), wraps=pycurl.Curl())
55 mockedCurl.perform.side_effect = Exception('mock error (ok)')
60 with mock.patch('arvados.keep.KeepClient.KeepService._get_user_agent', side_effect=q.get_nowait):
61 self.pool_test(os.path.join(self.mnt, 'zzz'))
62 self.assertTrue(mockedCurl.perform.called)
64 def _test_retry_write(self, tmp):
65 with open(os.path.join(tmp, 'foo'), 'w') as f:
67 json.load(open(os.path.join(tmp, '.arvados#collection')))