1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
10 from apiclient import http as apiclient_http
11 from unittest import mock
14 from . import run_test_server
15 from . import arvados_testutil as tutil
18 class ApiClientRetryTestMixin(object):
20 TEST_UUID = 'zzzzz-zzzzz-zzzzzzzzzzzzzzz'
21 TEST_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0'
28 # Patch arvados.api() to return our mock API, so we can mock
30 self.api_client = arvados.api('v1', cache=False, num_retries=0)
31 self.api_patch = mock.patch('arvados.api', return_value=self.api_client)
32 self.api_patch.start()
38 raise NotImplementedError("test subclasses must define run_method")
40 def test_immediate_success(self):
41 with tutil.mock_api_responses(self.api_client, '{}', [200]):
44 def test_immediate_failure(self):
45 with tutil.mock_api_responses(self.api_client, '{}', [400]), self.assertRaises(self.DEFAULT_EXCEPTION):
48 def test_retry_then_success(self):
49 with tutil.mock_api_responses(self.api_client, '{}', [500, 200]):
52 def test_error_after_default_retries_exhausted(self):
53 with tutil.mock_api_responses(self.api_client, '{}', [500, 500, 500, 500, 500, 500, 200]), self.assertRaises(self.DEFAULT_EXCEPTION):
56 def test_no_retry_after_immediate_success(self):
57 with tutil.mock_api_responses(self.api_client, '{}', [200, 400]):