-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1006 from ATIX-AG/add-csv-to-performance
Improve performance test to save test results in csv files
- Loading branch information
Showing
4 changed files
with
129 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,68 @@ | ||
"""Tests that sync deb plugin repositories.""" | ||
import pytest | ||
|
||
from pulp_deb.tests.performance.utils import write_csv_to_tmp | ||
from pulp_deb.tests.functional.constants import ( | ||
DEB_PERF_BOOKWORN, | ||
DEB_PERF_DEBIAN_URL, | ||
DEB_PERF_JAMMY, | ||
DEB_PERF_UBUNTU_URL, | ||
) | ||
|
||
perf_sync_test_params = [ | ||
pytest.param( | ||
DEB_PERF_UBUNTU_URL, | ||
DEB_PERF_JAMMY, | ||
True, | ||
"pulp-deb-performance-sync-tests-ubuntu-jammy", | ||
id="performance-sync-ubuntu-jammy-with-resync", | ||
), | ||
pytest.param( | ||
DEB_PERF_DEBIAN_URL, | ||
DEB_PERF_BOOKWORN, | ||
True, | ||
"pulp-deb-performance-sync-tests-debian-bookworm", | ||
id="performance-sync-debian-bookworm-with-resync", | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.parallel | ||
@pytest.mark.parametrize( | ||
"url,remote_args,resync", | ||
[ | ||
(DEB_PERF_UBUNTU_URL, DEB_PERF_JAMMY, True), | ||
(DEB_PERF_DEBIAN_URL, DEB_PERF_BOOKWORN, True), | ||
], | ||
) | ||
def test_deb_sync(deb_init_and_sync, url, remote_args, resync): | ||
@pytest.mark.parametrize("url,remote_args,resync,csv_filename", perf_sync_test_params) | ||
def test_deb_sync(deb_init_and_sync, url, remote_args, resync, csv_filename): | ||
"""Sync repositories with the deb plugin.""" | ||
# Create repository & remote and sync | ||
repo, remote, task = deb_init_and_sync(url=url, remote_args=remote_args, return_task=True) | ||
|
||
task_duration = task.finished_at - task.started_at | ||
waiting_time = task.started_at - task.pulp_created | ||
print( | ||
"\n-> Sync => Waiting time (s): {wait} | Service time (s): {service}".format( | ||
wait=waiting_time.total_seconds(), service=task_duration.total_seconds() | ||
) | ||
) | ||
task_time = (task.finished_at - task.started_at).total_seconds() | ||
wait_time = (task.started_at - task.pulp_created).total_seconds() | ||
print(f"\n-> Sync => Waiting time (s): {wait_time} | Service time (s): {task_time}") | ||
|
||
if resync: | ||
# Sync the repository again. | ||
latest_version_href = repo.latest_version_href | ||
repo, _, task = deb_init_and_sync(repository=repo, remote=remote, return_task=True) | ||
|
||
task_duration = task.finished_at - task.started_at | ||
waiting_time = task.started_at - task.pulp_created | ||
task_time_resync = (task.finished_at - task.started_at).total_seconds() | ||
wait_time_resync = (task.started_at - task.pulp_created).total_seconds() | ||
print( | ||
"\n-> Re-sync => Waiting time (s): {wait} | Service time (s): {service}".format( | ||
wait=waiting_time.total_seconds(), service=task_duration.total_seconds() | ||
) | ||
f"\n-> Resync => Wait time (s): {wait_time_resync} | Task time (s): {task_time_resync}" | ||
) | ||
|
||
# Check that nothing has changed since the last sync. | ||
assert latest_version_href == repo.latest_version_href | ||
|
||
write_csv_to_tmp( | ||
csv_filename, | ||
[ | ||
"task_duration_initial", | ||
"waiting_time_initial", | ||
"task_duration_resync", | ||
"waiting_time_resync", | ||
], | ||
[task_time, wait_time, task_time_resync, wait_time_resync], | ||
) | ||
else: | ||
write_csv_to_tmp( | ||
csv_filename, ["task_duration_initial", "waiting_time_initial"], [task_time, wait_time] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# coding=utf-8 | ||
"""Utilities for testing deb performance""" | ||
import csv | ||
|
||
from datetime import datetime | ||
|
||
|
||
def write_csv_to_tmp(basename, header_row, content_row, add_date=True, dateformat="%d.%m.%y"): | ||
"""Write a CSV file with a header and a single content row to the /tmp/ folder. | ||
:param basename: The basename of the csv file. | ||
:param header_row: The column header names. | ||
:param content_row: The line of data for the content columns. | ||
:param add_date: Whether the current date should be added to the csv. (default: True). | ||
:param dateformat: How the date should be formatted (default: %d.%m.%y). | ||
""" | ||
with open(f"/tmp/{basename}.csv", "w", encoding="UTF-8", newline="") as f: | ||
writer = csv.writer(f) | ||
if add_date: | ||
header_row.insert(0, "date") | ||
content_row.insert(0, datetime.strftime(datetime.now(), dateformat)) | ||
writer.writerow(header_row) | ||
writer.writerow(content_row) |