Skip to content

Commit

Permalink
test: run stuff in parallel
Browse files Browse the repository at this point in the history
Use filelock.FileLock to workaround the issue that session fixtures
do not work with xdist. This should probably be redone in some less
hard to read way :(
  • Loading branch information
mvo5 committed Jan 8, 2025
1 parent 40588c0 commit 16ee65b
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 241 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ jobs:
# podman needs (parts of) the environment but will break when
# XDG_RUNTIME_DIR is set.
# TODO: figure out what exactly podman needs
sudo -E XDG_RUNTIME_DIR= pytest-3 --basetemp=/mnt/var/tmp/bib-tests
# TODO2: figure out how much wecan run in parallel before running
# out of diskspace
sudo -E XDG_RUNTIME_DIR= pytest-3 --basetemp=/mnt/var/tmp/bib-tests -n 4
- name: Diskspace (after)
if: ${{ always() }}
run: |
Expand Down
7 changes: 7 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ def pytest_make_parametrize_id(config, val): # pylint: disable=W0613
if isinstance(val, TestCase):
return f"{val}"
return None


@pytest.fixture(name="shared_tmpdir", scope='session')
def shared_tmpdir_fixture(tmp_path_factory):
tmp_path = tmp_path_factory.getbasetemp().parent / "shared"
tmp_path.mkdir(exist_ok=True)
yield tmp_path
17 changes: 11 additions & 6 deletions test/containerbuild.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
import platform
import random
import string
Expand All @@ -7,6 +8,7 @@
from contextlib import contextmanager

import pytest
from filelock import FileLock


@contextmanager
Expand All @@ -33,17 +35,20 @@ def make_container(container_path, arch=None):


@pytest.fixture(name="build_container", scope="session")
def build_container_fixture():
def build_container_fixture(shared_tmpdir):
"""Build a container from the Containerfile and returns the name"""
if tag_from_env := os.getenv("BIB_TEST_BUILD_CONTAINER_TAG"):
return tag_from_env

container_tag = "bootc-image-builder-test"
subprocess.check_call([
"podman", "build",
"-f", "Containerfile",
"-t", container_tag,
])
with FileLock(shared_tmpdir / pathlib.Path(container_tag + ".lock")):
if not os.path.exists(shared_tmpdir / container_tag):
subprocess.check_call([
"podman", "build",
"-f", "Containerfile",
"-t", container_tag,
])
(shared_tmpdir / container_tag).write_text("done")
return container_tag


Expand Down
1 change: 1 addition & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ paramiko==2.12.0
boto3==1.33.13
qmp==1.1.0
pylint==3.2.5
xdist==3.6.1
Loading

0 comments on commit 16ee65b

Please sign in to comment.