Skip to content

Commit

Permalink
Fixed performance-tests.
Browse files Browse the repository at this point in the history
Moved fixtures shared between 'functional' and 'performance' up
one level.

Fixed some problems w/ the tests themselves as well.

fixes #3095
  • Loading branch information
ggainey committed Apr 4, 2023
1 parent e9b5047 commit 45649d6
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 133 deletions.
1 change: 1 addition & 0 deletions CHANGES/3095.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed performance-tests.
137 changes: 137 additions & 0 deletions pulp_rpm/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import uuid

import pytest

from pulpcore.client.pulp_rpm import (
ApiClient as RpmApiClient,
ContentRepoMetadataFilesApi,
DistributionsRpmApi,
PublicationsRpmApi,
RemotesRpmApi,
RepositoriesRpmApi,
RepositoriesRpmVersionsApi,
RpmRepositorySyncURL,
)

from pulp_rpm.tests.functional.constants import (
RPM_UNSIGNED_FIXTURE_URL,
)


@pytest.fixture(scope="session")
def rpm_publication_api(rpm_client):
"""Fixture for RPM publication API."""
return PublicationsRpmApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_repository_version_api(rpm_client):
"""Fixture for the RPM repository versions API."""
return RepositoriesRpmVersionsApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_distribution_api(rpm_client):
"""Fixture for RPM distribution API."""
return DistributionsRpmApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_client(bindings_cfg):
"""Fixture for RPM client."""
return RpmApiClient(bindings_cfg)


@pytest.fixture(scope="session")
def rpm_content_repometadata_files_api(rpm_client):
return ContentRepoMetadataFilesApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_rpmremote_api(rpm_client):
"""Fixture for RPM remote API."""
return RemotesRpmApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_repository_api(rpm_client):
"""Fixture for RPM repositories API."""
return RepositoriesRpmApi(rpm_client)


@pytest.fixture(scope="class")
def rpm_repository_factory(rpm_repository_api, gen_object_with_cleanup):
"""A factory to generate an RPM Repository with auto-deletion after the test run."""

def _rpm_repository_factory(**kwargs):
data = {"name": str(uuid.uuid4())}
data.update(kwargs)
return gen_object_with_cleanup(rpm_repository_api, data)

return _rpm_repository_factory


@pytest.fixture(scope="class")
def rpm_rpmremote_factory(rpm_rpmremote_api, gen_object_with_cleanup):
"""A factory to generate an RPM Remote with auto-deletion after the test run."""

def _rpm_rpmremote_factory(*, url=RPM_UNSIGNED_FIXTURE_URL, policy="immediate", **kwargs):
data = {"url": url, "policy": policy, "name": str(uuid.uuid4())}
data.update(kwargs)
return gen_object_with_cleanup(rpm_rpmremote_api, data)

return _rpm_rpmremote_factory


@pytest.fixture(scope="class")
def rpm_distribution_factory(rpm_distribution_api, gen_object_with_cleanup):
"""A factory to generate an RPM Distribution with auto-deletion after the test run."""

def _rpm_distribution_factory(**kwargs):
data = {"base_path": str(uuid.uuid4()), "name": str(uuid.uuid4())}
data.update(kwargs)
return gen_object_with_cleanup(rpm_distribution_api, data)

return _rpm_distribution_factory


@pytest.fixture(scope="class")
def rpm_publication_factory(rpm_publication_api, gen_object_with_cleanup):
"""A factory to generate an RPM Publication with auto-deletion after the test run."""

def _rpm_publication_factory(**kwargs):
# XOR check on repository and repository_version
assert bool("repository" in kwargs) ^ bool("repository_version" in kwargs)
return gen_object_with_cleanup(rpm_publication_api, kwargs)

return _rpm_publication_factory


@pytest.fixture(scope="class")
def init_and_sync(rpm_repository_factory, rpm_repository_api, rpm_rpmremote_factory, monitor_task):
"""Initialize a new repository and remote and sync the content from the passed URL."""

def _init_and_sync(
repository=None,
remote=None,
url=RPM_UNSIGNED_FIXTURE_URL,
policy="immediate",
sync_policy="additive",
skip_types=None,
return_task=False,
):
if repository is None:
repository = rpm_repository_factory()
if remote is None:
remote = rpm_rpmremote_factory(url=url, policy=policy)

repository_sync_data = RpmRepositorySyncURL(
remote=remote.pulp_href, sync_policy=sync_policy, skip_types=skip_types
)
sync_response = rpm_repository_api.sync(repository.pulp_href, repository_sync_data)
task = monitor_task(sync_response.task)

repository = rpm_repository_api.read(repository.pulp_href)
return (repository, remote) if not return_task else (repository, remote, task)

return _init_and_sync
128 changes: 0 additions & 128 deletions pulp_rpm/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,26 @@

from pulpcore.client.pulp_rpm import (
AcsRpmApi,
ApiClient as RpmApiClient,
ContentAdvisoriesApi,
ContentDistributionTreesApi,
ContentPackagecategoriesApi,
ContentPackagegroupsApi,
ContentPackagelangpacksApi,
ContentPackagesApi,
ContentRepoMetadataFilesApi,
DistributionsRpmApi,
ContentModulemdsApi,
ContentModulemdDefaultsApi,
ContentModulemdObsoletesApi,
PublicationsRpmApi,
RemotesRpmApi,
RemotesUlnApi,
RepositoriesRpmApi,
RepositoriesRpmVersionsApi,
RpmCopyApi,
RpmCompsApi,
RpmRepositorySyncURL,
)

from pulp_rpm.tests.functional.constants import (
RPM_KICKSTART_FIXTURE_URL,
RPM_SIGNED_URL,
RPM_UNSIGNED_FIXTURE_URL,
)


@pytest.fixture(scope="session")
def rpm_client(bindings_cfg):
"""Fixture for RPM client."""
return RpmApiClient(bindings_cfg)


@pytest.fixture(scope="session")
def rpm_repository_api(rpm_client):
"""Fixture for RPM repositories API."""
return RepositoriesRpmApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_repository_version_api(rpm_client):
"""Fixture for the RPM repository versions API."""
return RepositoriesRpmVersionsApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_rpmremote_api(rpm_client):
"""Fixture for RPM remote API."""
return RemotesRpmApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_ulnremote_api(rpm_client):
"""Fixture for RPM remote API."""
Expand All @@ -69,18 +36,6 @@ def rpm_acs_api(rpm_client):
return AcsRpmApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_publication_api(rpm_client):
"""Fixture for RPM publication API."""
return PublicationsRpmApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_distribution_api(rpm_client):
"""Fixture for RPM distribution API."""
return DistributionsRpmApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_package_api(rpm_client):
"""Fixture for RPM distribution API."""
Expand Down Expand Up @@ -140,11 +95,6 @@ def rpm_content_distribution_trees_api(rpm_client):
return ContentDistributionTreesApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_content_repometadata_files_api(rpm_client):
return ContentRepoMetadataFilesApi(rpm_client)


@pytest.fixture(scope="session")
def rpm_copy_api(rpm_client):
return RpmCopyApi(rpm_client)
Expand All @@ -157,84 +107,6 @@ def signed_artifact(http_get, artifacts_api_client, gen_object_with_cleanup, tmp
return gen_object_with_cleanup(artifacts_api_client, temp_file).to_dict()


@pytest.fixture(scope="class")
def rpm_repository_factory(rpm_repository_api, gen_object_with_cleanup):
"""A factory to generate an RPM Repository with auto-deletion after the test run."""

def _rpm_repository_factory(**kwargs):
data = {"name": str(uuid.uuid4())}
data.update(kwargs)
return gen_object_with_cleanup(rpm_repository_api, data)

return _rpm_repository_factory


@pytest.fixture(scope="class")
def rpm_rpmremote_factory(rpm_rpmremote_api, gen_object_with_cleanup):
"""A factory to generate an RPM Remote with auto-deletion after the test run."""

def _rpm_rpmremote_factory(*, url=RPM_UNSIGNED_FIXTURE_URL, policy="immediate", **kwargs):
data = {"url": url, "policy": policy, "name": str(uuid.uuid4())}
data.update(kwargs)
return gen_object_with_cleanup(rpm_rpmremote_api, data)

return _rpm_rpmremote_factory


@pytest.fixture(scope="class")
def rpm_publication_factory(rpm_publication_api, gen_object_with_cleanup):
"""A factory to generate an RPM Publication with auto-deletion after the test run."""

def _rpm_publication_factory(**kwargs):
# XOR check on repository and repository_version
assert bool("repository" in kwargs) ^ bool("repository_version" in kwargs)
return gen_object_with_cleanup(rpm_publication_api, kwargs)

return _rpm_publication_factory


@pytest.fixture(scope="class")
def rpm_distribution_factory(rpm_distribution_api, gen_object_with_cleanup):
"""A factory to generate an RPM Distribution with auto-deletion after the test run."""

def _rpm_distribution_factory(**kwargs):
data = {"base_path": str(uuid.uuid4()), "name": str(uuid.uuid4())}
data.update(kwargs)
return gen_object_with_cleanup(rpm_distribution_api, data)

return _rpm_distribution_factory


@pytest.fixture(scope="class")
def init_and_sync(rpm_repository_factory, rpm_repository_api, rpm_rpmremote_factory, monitor_task):
"""Initialize a new repository and remote and sync the content from the passed URL."""

def _init_and_sync(
repository=None,
remote=None,
url=RPM_UNSIGNED_FIXTURE_URL,
policy="immediate",
sync_policy="additive",
skip_types=None,
return_task=False,
):
if repository is None:
repository = rpm_repository_factory()
if remote is None:
remote = rpm_rpmremote_factory(url=url, policy=policy)

repository_sync_data = RpmRepositorySyncURL(
remote=remote.pulp_href, sync_policy=sync_policy, skip_types=skip_types
)
sync_response = rpm_repository_api.sync(repository.pulp_href, repository_sync_data)
task = monitor_task(sync_response.task)

repository = rpm_repository_api.read(repository.pulp_href)
return (repository, remote) if not return_task else (repository, remote, task)

return _init_and_sync


@pytest.fixture(scope="class")
def rpm_unsigned_repo_immediate(init_and_sync):
repo, _ = init_and_sync()
Expand Down
12 changes: 9 additions & 3 deletions pulp_rpm/tests/performance/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def parse_date_from_string(s, parse_format="%Y-%m-%dT%H:%M:%S.%fZ"):
:param parse_format: str defaults to %Y-%m-%dT%H:%M:%S.%fZ
:return: datetime.datetime
"""
return datetime.strptime(s, parse_format)
if isinstance(s, datetime):
return s
else:
return datetime.strptime(s, parse_format)


@pytest.fixture
Expand Down Expand Up @@ -80,7 +83,7 @@ def _extra_test(publication_href):
[
(EPEL7_URL, None),
(CENTOS7_URL, None),
(CENTOS8_STREAM_BASEOS_URL, centos_8stream_baseos_extra_tests),
(CENTOS8_STREAM_BASEOS_URL, "centos_8stream_baseos_extra_tests"),
(CENTOS8_STREAM_APPSTREAM_URL, None),
(CENTOS8_STREAM_BASEOS_URL, None),
],
Expand All @@ -93,6 +96,7 @@ def test_rpm_publish(
rpm_publication_api,
monitor_task,
delete_orphans_pre,
request,
):
"""Publish repositories with the rpm plugin.
Expand Down Expand Up @@ -136,4 +140,6 @@ def test_rpm_publish(
)
)
if extra_tests:
extra_tests(task.created_resources[0])
# fixtures and parameterization don't like each other - this hack gets us around that
xtra_fn = request.getfixturevalue(extra_tests)
xtra_fn(task.created_resources[0])
4 changes: 3 additions & 1 deletion pulp_rpm/tests/performance/test_pulp_to_pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def test_pulp_to_pulp(
distribution = rpm_distribution_factory(publication=publication.pulp_href)

# Create another repo pointing to distribution base_url
repo2, remote2, task = init_and_sync(url=distribution.base_url, policy="on_demand")
repo2, remote2, task = init_and_sync(
url=distribution.base_url, policy="on_demand", return_task=True
)
task_duration = task.finished_at - task.started_at
waiting_time = task.started_at - task.pulp_created
print(
Expand Down
5 changes: 4 additions & 1 deletion pulp_rpm/tests/performance/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def parse_date_from_string(s, parse_format="%Y-%m-%dT%H:%M:%S.%fZ"):
:param parse_format: str defaults to %Y-%m-%dT%H:%M:%S.%fZ
:return: datetime.datetime
"""
return datetime.strptime(s, parse_format)
if isinstance(s, datetime):
return s
else:
return datetime.strptime(s, parse_format)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 45649d6

Please sign in to comment.