2 import arvados_fuse.command
12 from .integration_test import IntegrationTest
15 class KeepClientRetry(unittest.TestCase):
16 origKeepClient = arvados.keep.KeepClient
19 self.mnt = tempfile.mkdtemp()
20 run_test_server.authorize_with('active')
25 @mock.patch('arvados_fuse.arvados.keep.KeepClient')
26 def _test_retry(self, num_retries, argv, kc):
27 kc.side_effect = lambda *args, **kw: self.origKeepClient(*args, **kw)
28 with arvados_fuse.command.Mount(
29 arvados_fuse.command.ArgumentParser().parse_args(
32 self.assertEqual(num_retries, kc.call_args[1].get('num_retries'))
34 def test_default_retry_3(self):
35 self._test_retry(3, [])
37 def test_retry_2(self):
38 self._test_retry(2, ['--retries=2'])
40 def test_no_retry(self):
41 self._test_retry(0, ['--retries=0'])
43 class RetryPUT(IntegrationTest):
44 @mock.patch('time.sleep')
45 @IntegrationTest.mount(argv=['--read-write', '--mount-tmp=zzz'])
46 def test_retry_write(self, sleep):
47 mockedCurl = mock.Mock(spec=pycurl.Curl(), wraps=pycurl.Curl())
48 mockedCurl.perform.side_effect = Exception('mock error (ok)')
53 with mock.patch('arvados.keep.KeepClient.KeepService._get_user_agent', side_effect=lambda: q.get(block=None)):
54 self.pool_test(os.path.join(self.mnt, 'zzz'))
55 self.assertTrue(mockedCurl.perform.called)
57 def _test_retry_write(self, tmp):
58 with open(os.path.join(tmp, 'foo'), 'w') as f:
60 json.load(open(os.path.join(tmp, '.arvados#collection')))