Skip to content

Commit 4fe7060

Browse files
committed
Add ability to run tests in parallel [PULP-753]
1 parent 6a889a1 commit 4fe7060

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+390
-398
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,5 @@ jobs:
115115
PULP_ENABLED_PLUGINS: "${{ matrix.pulp_enabled_plugins }}"
116116
OAS_VERSION: "${{ matrix.oas_version }}"
117117
run: |
118-
.ci/run_container.sh make livetest
118+
.ci/run_container.sh make paralleltest
119119
...

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ test: | tests/cli.toml
4242
livetest: | tests/cli.toml
4343
python3 -m pytest -v tests pulp-glue/tests -m live
4444

45+
.PHONY: paralleltest
46+
paralleltest: | tests/cli.toml
47+
python3 -m pytest -v tests pulp-glue/tests -m live -n 8
48+
4549
.PHONY: unittest
4650
unittest:
4751
python3 -m pytest -v tests pulp-glue/tests cookiecutter/pulp_filter_extension.py -m "not live"

cookiecutter/ci/cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"current_version": "0.0.1.dev",
99
"test_matrix": null,
1010
"unittests": false,
11+
"paralleltests": false,
1112
"__app_label_suffix": "{{ cookiecutter.app_label and '-' + cookiecutter.app_label }}",
1213
"__project_name": "pulp-cli{{ cookiecutter.__app_label_suffix }}",
1314
"repository": "https://github.com/pulp/{{ cookiecutter.__project_name }}",

cookiecutter/ci/{{ cookiecutter.__project_name }}/.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ jobs:
8787
OAS_VERSION: "${{ matrix.oas_version }}"
8888
{%- endraw %}
8989
run: |
90-
.ci/run_container.sh make {% if cookiecutter.unittests %}live{% endif %}test
90+
.ci/run_container.sh make {% if cookiecutter.paralleltests %}parallel{% elif cookiecutter.unittests %}live{% endif %}test
9191
...

cookiecutter/ci/{{ cookiecutter.__project_name }}/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ test: | tests/cli.toml
5757
livetest: | tests/cli.toml
5858
python3 -m pytest -v tests {%- if cookiecutter.glue %} pulp-glue{{ cookiecutter.__app_label_suffix }}/tests {%- endif %} -m live
5959

60+
.PHONY: paralleltest
61+
paralleltest: | tests/cli.toml
62+
python3 -m pytest -v tests {%- if cookiecutter.glue %} pulp-glue{{ cookiecutter.__app_label_suffix }}/tests {%- endif %} -m live -n 8
63+
6064
.PHONY: unittest
6165
unittest:
6266
python3 -m pytest -v tests {%- if cookiecutter.glue %} pulp-glue{{ cookiecutter.__app_label_suffix }}/tests {%- endif %}

cookiecutter/ci/{{ cookiecutter.__project_name }}/pyproject.toml.update

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ translations = {{ cookiecutter.translations | toml_value }}
2323
main_package = {{ cookiecutter.main_package | toml_value }}
2424
binary_dependencies = {{ cookiecutter.binary_dependencies | toml_value }}
2525
unittests = {{ cookiecutter.unittests | toml_value }}
26+
paralleltests = {{ cookiecutter.paralleltests | toml_value }}
2627

2728
[tool.bumpversion]
2829
# This section is managed by the cookiecutter templates.

pulpcore/cli/container/distribution.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pulp_glue.common.context import (
66
EntityDefinition,
77
EntityFieldDefinition,
8+
PluginRequirement,
89
PulpEntityContext,
910
PulpRepositoryContext,
1011
)
@@ -115,6 +116,9 @@ def update(
115116

116117
distribution: EntityDefinition = distribution_ctx.entity
117118
body: EntityDefinition = {}
119+
non_blocking = base_path is None and distribution_ctx.pulp_ctx.has_plugin(
120+
PluginRequirement("core", specifier=">=3.24.0")
121+
)
118122

119123
if private is not None:
120124
body["private"] = private
@@ -135,16 +139,18 @@ def update(
135139
repository = t.cast(PulpEntityContext, repository)
136140
if version is not None:
137141
if distribution["repository"]:
138-
distribution_ctx.update(body={"repository": ""}, non_blocking=True)
142+
distribution_ctx.update(body={"repository": ""}, non_blocking=non_blocking)
139143
body["repository_version"] = f"{repository.pulp_href}versions/{version}/"
140144
else:
141145
if distribution["repository_version"]:
142-
distribution_ctx.update(body={"repository_version": ""}, non_blocking=True)
146+
distribution_ctx.update(
147+
body={"repository_version": ""}, non_blocking=non_blocking
148+
)
143149
body["repository"] = repository.pulp_href
144150
elif version is not None:
145151
# keep current repository, change version
146152
if distribution["repository"]:
147-
distribution_ctx.update(body={"repository": ""}, non_blocking=True)
153+
distribution_ctx.update(body={"repository": ""}, non_blocking=non_blocking)
148154
body["repository_version"] = f"{distribution['repository']}versions/{version}/"
149155
elif distribution["repository_version"]:
150156
# 'dummy' vars are to get us around a mypy/1.2 complaint about '_'

pulpcore/cli/core/task.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ def cancel(
151151
states.append("running")
152152
if states:
153153
tasks = task_ctx.list(limit=1 << 64, offset=0, parameters={"state__in": states})
154+
if pulp_ctx.api._dry_run:
155+
raise click.ClickException(
156+
_("Trying to cancel {} tasks in safe-mode, aborting").format(len(tasks))
157+
)
154158
for task in tasks:
155159
task_ctx.cancel(task["pulp_href"], background=True)
156160
for task in tasks:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ translations = true
7575
main_package = "common"
7676
binary_dependencies = ""
7777
unittests = true
78+
paralleltests = true
7879

7980
[tool.bumpversion]
8081
# This section is managed by the cookiecutter templates.

test_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Test requirements
22
pytest>=7.0.0,<9.1
3+
pytest-xdist
34
pytest-subtests>=0.12.0,<0.16
45
python-gnupg>=0.5.0,<0.6
56
trustme>=1.1.0,<1.3

0 commit comments

Comments
 (0)