def test_svn_propget_retry_failure( mocker, tmp_path, sample_repo_with_externals_url, exception_to_retry ): svnrepo = SvnRepo( sample_repo_with_externals_url, sample_repo_with_externals_url, tmp_path, max_content_length=100000, ) checkout_path = os.path.join(tmp_path, "checkout") svnrepo.checkout( sample_repo_with_externals_url, checkout_path, svnrepo.head_revision(), ignore_externals=True, ) mock_sleep = mocker.patch.object(svnrepo.propget.retry, "sleep") nb_failed_calls = SVN_RETRY_MAX_ATTEMPTS svnrepo.client = SVNClientWrapper( svnrepo.client, exception_to_retry, nb_failed_calls ) with pytest.raises(type(exception_to_retry)): svnrepo.propget("svn:externals", checkout_path, None, None, True) assert_sleep_calls(mock_sleep, mocker, nb_failed_calls - 1)
def test_svn_info_retry_failure(mocker, tmp_path, sample_repo_url, exception_to_retry): svnrepo = SvnRepo( sample_repo_url, sample_repo_url, tmp_path, max_content_length=100000 ) mock_sleep = mocker.patch.object(svnrepo.info.retry, "sleep") nb_failed_calls = SVN_RETRY_MAX_ATTEMPTS svnrepo.client = SVNClientWrapper( svnrepo.client, exception_to_retry, nb_failed_calls ) with pytest.raises(type(exception_to_retry)): svnrepo.info(sample_repo_url) assert_sleep_calls(mock_sleep, mocker, nb_failed_calls - 1)
def test_svn_info_retry_success(mocker, tmp_path, sample_repo_url, exception_to_retry): svnrepo = SvnRepo( sample_repo_url, sample_repo_url, tmp_path, max_content_length=100000 ) mock_sleep = mocker.patch.object(svnrepo.info.retry, "sleep") nb_failed_calls = 2 svnrepo.client = SVNClientWrapper( svnrepo.client, exception_to_retry, nb_failed_calls ) info = svnrepo.info(sample_repo_url) assert info assert_sleep_calls(mock_sleep, mocker, nb_failed_calls)
def test_remote_access_retry_failure( mocker, tmp_path, sample_repo_url, exception_to_retry ): nb_failed_calls = SVN_RETRY_MAX_ATTEMPTS mock_ra = mocker.patch("swh.loader.svn.svn.RemoteAccess") remote_access = RemoteAccess(sample_repo_url, auth=Auth([get_username_provider()])) mock_ra.side_effect = ( [exception_to_retry] * nb_failed_calls + [remote_access] + [exception_to_retry] * nb_failed_calls + [remote_access] ) mock_sleep = mocker.patch.object(SvnRepo.remote_access.retry, "sleep") with pytest.raises(type(exception_to_retry)): SvnRepo( sample_repo_url, sample_repo_url, tmp_path, max_content_length=100000, ) assert_sleep_calls(mock_sleep, mocker, nb_failed_calls - 1)
def test_svn_commit_info_retry_success( mocker, tmp_path, sample_repo_url, exception_to_retry ): svnrepo = SvnRepo( sample_repo_url, sample_repo_url, tmp_path, max_content_length=100000 ) mock_sleep = mocker.patch.object(svnrepo.commit_info.retry, "sleep") nb_failed_calls = 2 svnrepo.conn_log = SVNRemoteAccessWrapper( svnrepo.conn_log, exception_to_retry, nb_failed_calls ) commit = svnrepo.commit_info(revision=1) assert commit assert_sleep_calls(mock_sleep, mocker, nb_failed_calls)
def test_svn_export_retry_success( mocker, tmp_path, sample_repo_url, exception_to_retry ): svnrepo = SvnRepo( sample_repo_url, sample_repo_url, tmp_path, max_content_length=100000 ) mock_sleep = mocker.patch.object(svnrepo.export.retry, "sleep") nb_failed_calls = 2 svnrepo.client = SVNClientWrapper( svnrepo.client, exception_to_retry, nb_failed_calls ) export_path = os.path.join(tmp_path, "export") svnrepo.export(sample_repo_url, export_path) assert os.path.exists(export_path) assert_sleep_calls(mock_sleep, mocker, nb_failed_calls)
def svn_repo(self, *args, **kwargs): """Wraps the creation of SvnRepo object and handles not found repository errors.""" try: return SvnRepo(*args, **kwargs) except SubversionException as e: error_msgs = [ "Unable to connect to a repository at URL", "Unknown URL type", "is not a working copy", ] for msg in error_msgs: if msg in e.args[0]: self._load_status = "uneventful" raise NotFound(e) raise
def test_remote_access_retry_success( mocker, tmp_path, sample_repo_url, exception_to_retry ): nb_failed_calls = 2 mock_ra = mocker.patch("swh.loader.svn.svn.RemoteAccess") remote_access = RemoteAccess(sample_repo_url, auth=Auth([get_username_provider()])) mock_ra.side_effect = ( [exception_to_retry] * nb_failed_calls + [remote_access] + [exception_to_retry] * nb_failed_calls + [remote_access] ) mock_sleep = mocker.patch.object(SvnRepo.remote_access.retry, "sleep") SvnRepo( sample_repo_url, sample_repo_url, tmp_path, max_content_length=100000, ) assert_sleep_calls(mock_sleep, mocker, nb_failed_calls)
def test_svn_checkout_retry_failure( mocker, tmp_path, sample_repo_url, exception_to_retry ): svnrepo = SvnRepo( sample_repo_url, sample_repo_url, tmp_path, max_content_length=100000 ) mock_sleep = mocker.patch.object(svnrepo.checkout.retry, "sleep") nb_failed_calls = SVN_RETRY_MAX_ATTEMPTS svnrepo.client = SVNClientWrapper( svnrepo.client, exception_to_retry, nb_failed_calls ) checkout_path = os.path.join(tmp_path, "checkout") with pytest.raises(type(exception_to_retry)): svnrepo.checkout(sample_repo_url, checkout_path, svnrepo.head_revision()) assert not os.path.exists(checkout_path) assert_sleep_calls(mock_sleep, mocker, nb_failed_calls - 1)