Skip to content

Commit

Permalink
Make libdnf5::repo::RepoSack::update_and_load_repos(...) private
Browse files Browse the repository at this point in the history
Switches unittests to use update_and_load_enabled_repos.
This means that both add_repo_repomd and add_repo_rpm can be called
together only once with load = true.
  • Loading branch information
kontura committed Mar 26, 2024
1 parent 0bc9975 commit 627ad27
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 79 deletions.
28 changes: 13 additions & 15 deletions include/libdnf5/repo/repo_sack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,6 @@ class RepoSack : public sack::Sack<Repo> {
void update_and_load_enabled_repos(const std::vector<Repo::Type> & types);


/// @warning This method is experimental/unstable and should not be relied on. It may be removed without warning
///
/// Downloads (if necessary) repository metadata and loads them in parallel.
///
/// Launches a thread that picks repos from a queue and loads them into
/// memory (calling their `load()` method). Then iterates over `repos`,
/// potentially downloads fresh metadata (by calling the
/// `download_metadata()` method) and then queues them for loading. This
/// speeds up the process by loading repos into memory while others are being
/// downloaded.
///
/// @param repos The repositories to update and load
/// @param import_keys If true, attempts to download and import keys for repositories that failed key validation
void update_and_load_repos(libdnf5::repo::RepoQuery & repos, bool import_keys = true);

RepoSackWeakPtr get_weak_ptr();

/// @return The `Base` object to which this object belongs.
Expand Down Expand Up @@ -176,6 +161,19 @@ class RepoSack : public sack::Sack<Repo> {
explicit RepoSack(const libdnf5::BaseWeakPtr & base);
explicit RepoSack(libdnf5::Base & base);

/// Downloads (if necessary) repository metadata and loads them in parallel.
///
/// Launches a thread that picks repos from a queue and loads them into
/// memory (calling their `load()` method). Then iterates over `repos`,
/// potentially downloads fresh metadata (by calling the
/// `download_metadata()` method) and then queues them for loading. This
/// speeds up the process by loading repos into memory while others are being
/// downloaded.
///
/// @param repos The repositories to update and load
/// @param import_keys If true, attempts to download and import keys for repositories that failed key validation
void update_and_load_repos(libdnf5::repo::RepoQuery & repos, bool import_keys = true);

/// Loads repositories configuration overrides from drop-in directories. No new repositories are created.
/// Only the configuration of the corresponding existing repositories is modified.
void load_repos_configuration_overrides();
Expand Down
24 changes: 12 additions & 12 deletions test/libdnf5/comps/test_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void CompsEnvironmentTest::test_load_defaults() {

void CompsEnvironmentTest::test_merge() {
// Load multiple different definitions of the minimal environment
add_repo_repomd("repomd-comps-minimal-environment");
add_repo_repomd("repomd-comps-custom-environment");
add_repo_repomd("repomd-comps-minimal-environment", false);
add_repo_repomd("repomd-comps-custom-environment", false);
add_repo_repomd("repomd-comps-minimal-environment-v2");

// The "Minimal Install v2" is preferred because its repoid is alphabetically higher
Expand All @@ -86,8 +86,8 @@ void CompsEnvironmentTest::test_merge() {
void CompsEnvironmentTest::test_merge_when_different_load_order() {
// Load multiple different definitions of the minimal environment
// The order of loading the repositories does not matter
add_repo_repomd("repomd-comps-minimal-environment-v2");
add_repo_repomd("repomd-comps-custom-environment");
add_repo_repomd("repomd-comps-minimal-environment-v2", false);
add_repo_repomd("repomd-comps-custom-environment", false);
add_repo_repomd("repomd-comps-minimal-environment");

// The "Minimal Install v2" is preferred because its repoid is alphabetically higher
Expand All @@ -106,8 +106,8 @@ void CompsEnvironmentTest::test_merge_when_different_load_order() {

void CompsEnvironmentTest::test_merge_with_empty() {
// Load minimal environment and another definition with all attributes empty
add_repo_repomd("repomd-comps-minimal-environment");
add_repo_repomd("repomd-comps-custom-environment");
add_repo_repomd("repomd-comps-minimal-environment", false);
add_repo_repomd("repomd-comps-custom-environment", false);
add_repo_repomd("repomd-comps-minimal-environment-empty");

// All the attributes are taken from the non-empty definition
Expand All @@ -127,8 +127,8 @@ void CompsEnvironmentTest::test_merge_with_empty() {

void CompsEnvironmentTest::test_merge_empty_with_nonempty() {
// Load minimal environment and another definition with all attributes empty
add_repo_repomd("repomd-comps-minimal-environment-empty");
add_repo_repomd("repomd-comps-custom-environment");
add_repo_repomd("repomd-comps-minimal-environment-empty", false);
add_repo_repomd("repomd-comps-custom-environment", false);
add_repo_repomd("repomd-comps-minimal-environment");

// All the attributes are taken from the non-empty definition
Expand All @@ -148,7 +148,7 @@ void CompsEnvironmentTest::test_merge_empty_with_nonempty() {

void CompsEnvironmentTest::test_merge_different_translations() {
// Load different definitions of the minimal environment with different set of translations
add_repo_repomd("repomd-comps-minimal-environment");
add_repo_repomd("repomd-comps-minimal-environment", false);
add_repo_repomd("repomd-comps-minimal-environment-different-translations");

EnvironmentQuery q_minimal_env(base);
Expand Down Expand Up @@ -191,9 +191,9 @@ void CompsEnvironmentTest::test_serialize() {


void CompsEnvironmentTest::test_solvables() {
add_repo_repomd("repomd-comps-minimal-environment");
add_repo_repomd("repomd-comps-core");
add_repo_repomd("repomd-comps-core-environment");
add_repo_repomd("repomd-comps-minimal-environment", false);
add_repo_repomd("repomd-comps-core", false);
add_repo_repomd("repomd-comps-core-environment", false);
add_repo_repomd("repomd-comps-standard");

EnvironmentQuery q_environments(base);
Expand Down
8 changes: 4 additions & 4 deletions test/libdnf5/comps/test_environment_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ using namespace libdnf5::comps;

void CompsEnvironmentQueryTest::setUp() {
BaseTestCase::setUp();
add_repo_repomd("repomd-comps-core-environment");
add_repo_repomd("repomd-comps-custom-environment");
add_repo_repomd("repomd-comps-minimal-environment");
add_repo_repomd("repomd-comps-minimal-environment-empty");
add_repo_repomd("repomd-comps-core-environment", false);
add_repo_repomd("repomd-comps-custom-environment", false);
add_repo_repomd("repomd-comps-minimal-environment", false);
add_repo_repomd("repomd-comps-minimal-environment-empty", false);
add_repo_repomd("repomd-comps-minimal-environment-v2");
}

Expand Down
29 changes: 14 additions & 15 deletions test/libdnf5/comps/test_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ using namespace libdnf5::comps;


void CompsGroupTest::test_load() {
add_repo_repomd("repomd-comps-core");
add_repo_repomd("repomd-comps-core", false);
add_repo_repomd("repomd-comps-standard");

GroupQuery q_core(base);
q_core.filter_installed(false);
Expand All @@ -82,8 +83,6 @@ void CompsGroupTest::test_load() {
Package("dnf-plugins-core", PackageType::OPTIONAL, "")};
CPPUNIT_ASSERT_EQUAL(exp_pkgs_core, core.get_packages());

add_repo_repomd("repomd-comps-standard");

GroupQuery q_standard(base);
q_standard.filter_installed(false);
q_standard.filter_groupid("standard");
Expand Down Expand Up @@ -132,8 +131,8 @@ void CompsGroupTest::test_load_defaults() {

void CompsGroupTest::test_merge() {
// Load multiple different definitions of the core group
add_repo_repomd("repomd-comps-core");
add_repo_repomd("repomd-comps-standard");
add_repo_repomd("repomd-comps-core", false);
add_repo_repomd("repomd-comps-standard", false);
add_repo_repomd("repomd-comps-core-v2");

// The "Core v2" is preferred because its repoid is alphabetically higher
Expand Down Expand Up @@ -165,8 +164,8 @@ void CompsGroupTest::test_merge() {
void CompsGroupTest::test_merge_when_different_load_order() {
// Load multiple different definitions of the core group
// The order of loading the repositories does not matter
add_repo_repomd("repomd-comps-core-v2");
add_repo_repomd("repomd-comps-standard");
add_repo_repomd("repomd-comps-core-v2", false);
add_repo_repomd("repomd-comps-standard", false);
add_repo_repomd("repomd-comps-core");

// The "Core v2" is preferred because its repoid is alphabetically higher
Expand Down Expand Up @@ -197,8 +196,8 @@ void CompsGroupTest::test_merge_when_different_load_order() {

void CompsGroupTest::test_merge_with_empty() {
// Load core group and another definition with all attributes empty
add_repo_repomd("repomd-comps-core");
add_repo_repomd("repomd-comps-standard");
add_repo_repomd("repomd-comps-core", false);
add_repo_repomd("repomd-comps-standard", false);
add_repo_repomd("repomd-comps-core-empty");

// All the attributes are taken from the non-empty definition except for boolean values
Expand All @@ -224,8 +223,8 @@ void CompsGroupTest::test_merge_with_empty() {

void CompsGroupTest::test_merge_empty_with_nonempty() {
// Load core group and another definition with all attributes empty
add_repo_repomd("repomd-comps-core-v2");
add_repo_repomd("repomd-comps-standard");
add_repo_repomd("repomd-comps-core-v2", false);
add_repo_repomd("repomd-comps-standard", false);
add_repo_repomd("repomd-comps-core-empty");

// All the attributes are taken from the non-empty definition
Expand Down Expand Up @@ -254,7 +253,7 @@ void CompsGroupTest::test_merge_empty_with_nonempty() {

void CompsGroupTest::test_merge_different_translations() {
// Load different definitions of the core group with different set of translations
add_repo_repomd("repomd-comps-core");
add_repo_repomd("repomd-comps-core", false);
add_repo_repomd("repomd-comps-core-different-translations");

GroupQuery q_core(base);
Expand Down Expand Up @@ -293,9 +292,9 @@ void CompsGroupTest::test_serialize() {


void CompsGroupTest::test_solvables() {
add_repo_repomd("repomd-comps-minimal-environment");
add_repo_repomd("repomd-comps-core");
add_repo_repomd("repomd-comps-core-environment");
add_repo_repomd("repomd-comps-minimal-environment", false);
add_repo_repomd("repomd-comps-core", false);
add_repo_repomd("repomd-comps-core-environment", false);
add_repo_repomd("repomd-comps-standard");

libdnf5::comps::GroupQuery q_groups(base);
Expand Down
8 changes: 4 additions & 4 deletions test/libdnf5/comps/test_group_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ using namespace libdnf5::comps;

void CompsGroupQueryTest::setUp() {
BaseTestCase::setUp();
add_repo_repomd("repomd-comps-core");
add_repo_repomd("repomd-comps-core-empty");
add_repo_repomd("repomd-comps-core-different-translations");
add_repo_repomd("repomd-comps-critical-path-standard");
add_repo_repomd("repomd-comps-core", false);
add_repo_repomd("repomd-comps-core-empty", false);
add_repo_repomd("repomd-comps-core-different-translations", false);
add_repo_repomd("repomd-comps-critical-path-standard", false);
add_repo_repomd("repomd-comps-standard");
}

Expand Down
8 changes: 5 additions & 3 deletions test/libdnf5/module/test_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void ModuleTest::test_query() {
}

void ModuleTest::test_query_latest() {
add_repo_repomd("repomd-modules");
add_repo_repomd("repomd-modules", false);
add_repo_repomd("repomd-modules-duplicit");

{ // Check we can see all the modules, even ones with duplicit nscva
Expand Down Expand Up @@ -801,13 +801,15 @@ void ModuleTest::test_module_disable_enabled() {


void ModuleTest::test_module_reset() {
add_repo_repomd("repomd-modules");

// Set state of module berries to ENABLED
// This has to be done before the repos are loaded and modules initialized
// in update_and_load_enabled_repos in add_repo_repomd.
(base.*get(priv_impl()))
->get_system_state()
.set_module_state("berries", libdnf5::system::ModuleState({"main", ModuleStatus::ENABLED, {}}));

add_repo_repomd("repomd-modules");

// Add module reset goal operation
libdnf5::Goal goal(base);
goal.add_module_reset("berries", libdnf5::GoalJobSettings());
Expand Down
15 changes: 7 additions & 8 deletions test/libdnf5/repo/test_repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ void RepoTest::test_load_repo() {
auto cbs = callbacks.get();
repo->set_callbacks(std::move(callbacks));

libdnf5::repo::RepoQuery repos(base);
repos.filter_id(repoid);
repo_sack->update_and_load_repos(repos);
repo_sack->update_and_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE});

CPPUNIT_ASSERT_EQUAL(1, dl_callbacks_ptr->start_cnt);
CPPUNIT_ASSERT_EQUAL(repoid, dl_callbacks_ptr->start_what);
Expand All @@ -134,17 +132,18 @@ void RepoTest::test_load_repo_nonexistent() {
auto repo = add_repo(repoid, "/path/thats/not/here", false);
repo->get_config().get_skip_if_unavailable_option().set(false);

libdnf5::repo::RepoQuery repos(base);
repos.filter_id(repoid);
CPPUNIT_ASSERT_THROW(repo_sack->update_and_load_repos(repos), libdnf5::repo::RepoDownloadError);
CPPUNIT_ASSERT_THROW(
repo_sack->update_and_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE}),
libdnf5::repo::RepoDownloadError);
}

void RepoTest::test_update_and_load_enabled_repos_twice_fails() {
// Call this once...
repo_sack->update_and_load_enabled_repos(true);
repo_sack->update_and_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE});

// calling this again should fail
CPPUNIT_ASSERT_THROW(repo_sack->update_and_load_enabled_repos(true), libdnf5::UserAssertionError);
CPPUNIT_ASSERT_THROW(
repo_sack->update_and_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE}), libdnf5::UserAssertionError);
}

void RepoTest::test_update_and_load_enabled_repos_empty() {
Expand Down
4 changes: 1 addition & 3 deletions test/perl5/libdnf5/rpm/test_package_query.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ my $repo_cfg = $repo->get_config();
$repo_cfg->get_baseurl_option()->set($libdnf5::conf::Option::Priority_RUNTIME, $baseurl);

# fetch repo metadata and load it
my $repos = new libdnf5::repo::RepoQuery($base);
$repos->filter_id($repoid);
$repo_sack->update_and_load_repos($repos);
$repo_sack->update_and_load_enabled_repos(new libdnf5::repo::VectorRepoType(1, $libdnf5::repo::Repo::Type::AVAILABLE));

#test_size()
{
Expand Down
4 changes: 1 addition & 3 deletions test/python3/libdnf5/base_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def _add_repo(self, repoid, repo_path, load=True):
repo.get_config().baseurl = "file://" + repo_path

if load:
repos = libdnf5.repo.RepoQuery(self.base)
repos.filter_id(repoid)
self.repo_sack.update_and_load_repos(repos)
self.repo_sack.update_and_load_enabled_repos(libdnf5.repo.VectorRepoType(1, libdnf5.repo.Repo.Type_AVAILABLE))

return repo

Expand Down
4 changes: 1 addition & 3 deletions test/python3/libdnf5/repo/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def test_load_repo(self):
# can be passed directly to repo.set_callbacks
repo.set_callbacks(libdnf5.repo.RepoCallbacksUniquePtr(cbs))

repos = libdnf5.repo.RepoQuery(self.base)
repos.filter_id(repoid)
self.repo_sack.update_and_load_repos(repos)
self.repo_sack.update_and_load_enabled_repos(libdnf5.repo.VectorRepoType(1, libdnf5.repo.Repo.Type_AVAILABLE))

self.assertEqual(dl_cbs.start_cnt, 1)
self.assertEqual(dl_cbs.start_what, repoid)
Expand Down
4 changes: 1 addition & 3 deletions test/ruby/libdnf5/base_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def _add_repo(repoid, repo_path, load=true)
repo.get_config().get_baseurl_option().set("file://" + repo_path)

if load
repos = Repo::RepoQuery.new(@base)
repos.filter_id(repoid)
@repo_sack.update_and_load_repos(repos)
@repo_sack.update_and_load_enabled_repos(Repo::VectorRepoType.new(1, Repo::Repo::Type_AVAILABLE))
end

return repo
Expand Down
5 changes: 2 additions & 3 deletions test/ruby/libdnf5/repo/test_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
include Test::Unit::Assertions

require 'libdnf5/base'
require 'libdnf5/repo'

require 'base_test_case'

Expand Down Expand Up @@ -100,9 +101,7 @@ def test_load_repo()
cbs = RepoCallbacks.new()
repo.set_callbacks(Repo::RepoCallbacksUniquePtr.new(cbs))

repos = Repo::RepoQuery.new(@base)
repos.filter_id(repoid)
@repo_sack.update_and_load_repos(repos)
@repo_sack.update_and_load_enabled_repos(Repo::VectorRepoType.new(1, Repo::Repo::Type_AVAILABLE))

assert_equal(1, dl_cbs.start_cnt)
assert_equal(repoid, dl_cbs.start_what)
Expand Down
4 changes: 1 addition & 3 deletions test/shared/base_test_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ libdnf5::repo::RepoWeakPtr BaseTestCase::add_repo(
repo->get_config().get_baseurl_option().set("file://" + repo_path);

if (load) {
libdnf5::repo::RepoQuery repos(base);
repos.filter_id(repoid);
repo_sack->update_and_load_repos(repos);
repo_sack->update_and_load_enabled_repos({libdnf5::repo::Repo::Type::AVAILABLE});
}

return repo;
Expand Down
2 changes: 2 additions & 0 deletions test/shared/base_test_case.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ class BaseTestCase : public TestCaseFixture {
libdnf5::repo::RepoWeakPtr add_repo(const std::string & repoid, const std::string & repo_path, bool load = true);

// Add (load) a repo from PROJECT_SOURCE_DIR/test/data/repos-repomd/<repoid>/repodata
// Both add_repo_repomd and add_repo_rpm can be called together only once with load = true
libdnf5::repo::RepoWeakPtr add_repo_repomd(const std::string & repoid, bool load = true);

// Add (load) a repo from PROJECT_BINARY_DIR/test/data/repos-rpm/<repoid>/repodata
// Both add_repo_repomd and add_repo_rpm can be called together only once with load = true
libdnf5::repo::RepoWeakPtr add_repo_rpm(const std::string & repoid, bool load = true);

// Add (load) a repo from PROJECT_SOURCE_DIR/test/data/repos-solv/<repoid>.repo
Expand Down

0 comments on commit 627ad27

Please sign in to comment.