Skip to content

Commit c44ef52

Browse files
committed
FIXUP: Make test parallel friendly
This doesn't fully work: Actually running tests in parallel causes podman hiccups: ``` Error: reading CIDFile: open /tmp/tmplgrkkdaq/cidfile: no such file or directory RuntimeError: Failed to create container ```
1 parent 8ee38d0 commit c44ef52

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

test/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def pytest_exception_interact(node, call, report):
2020
else:
2121
print('\n\n---------- cockpit-tasks log ------------')
2222
sys.stdout.flush()
23-
subprocess.run(['podman', 'exec', '-i', 'cockpituous-tasks', 'cat', '/tmp/cockpit-tasks.log'])
23+
subprocess.run(['podman', 'exec', '-i', f'cockpituous-tasks-{os.getpid()}',
24+
'cat', '/tmp/cockpit-tasks.log'])
2425
print('-----------------------------------------')
2526
sys.stdout.flush()

test/test_deployment.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
from pytest_container.pod import Pod, PodData, PodLauncher
1818
from testinfra.host import Host
1919

20+
# we want to have useful pod/container names for interactive debugging and log dumping, but still allow parallel tests
21+
# (with e.g. xdist) so disambiguate them with the pid
22+
TEST_INSTANCE = str(os.getpid())
23+
2024
TASKS_IMAGE = os.environ.get('TASKS_IMAGE', 'ghcr.io/cockpit-project/tasks:latest')
2125
ROOT_DIR = Path(__file__).parent.parent
2226
COMMON_LAUNCH_ARGS = ['--stop-timeout=0', '--security-opt=label=disable']
@@ -113,7 +117,7 @@ def pod(config: Config, pytestconfig) -> PodData:
113117
# RabbitMQ
114118
containers.append(Container(
115119
url='docker.io/rabbitmq',
116-
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', 'cockpituous-rabbitmq'],
120+
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', f'cockpituous-rabbitmq-{TEST_INSTANCE}'],
117121
volume_mounts=[
118122
BindMount('/etc/rabbitmq', host_path=config.rabbitmq, flags=[VolumeFlag.READ_ONLY]),
119123
BindMount('/run/secrets/webhook', host_path=config.webhook, flags=[VolumeFlag.READ_ONLY]),
@@ -123,7 +127,7 @@ def pod(config: Config, pytestconfig) -> PodData:
123127
# minio S3 store
124128
containers.append(Container(
125129
url='quay.io/minio/minio',
126-
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', 'cockpituous-s3'],
130+
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', f'cockpituous-s3-{TEST_INSTANCE}'],
127131
# that's what we want, but not in latest release yet: https://github.com/dcermak/pytest_container/issues/182
128132
# extra_entrypoint_args=['server', '/data', '--console-address', ':9001'],
129133
entry_point=EntrypointSelection.BASH,
@@ -143,7 +147,7 @@ def pod(config: Config, pytestconfig) -> PodData:
143147
containers.append(Container(
144148
url='quay.io/minio/mc',
145149
custom_entry_point='/bin/sh',
146-
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', 'cockpituous-mc'],
150+
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', f'cockpituous-mc-{TEST_INSTANCE}'],
147151
volume_mounts=[
148152
BindMount('/etc/pki/ca-trust/source/anchors/ca.pem', host_path=config.secrets / 'ca.pem',
149153
flags=[VolumeFlag.READ_ONLY]),
@@ -153,7 +157,7 @@ def pod(config: Config, pytestconfig) -> PodData:
153157
# tasks
154158
containers.append(Container(
155159
url=TASKS_IMAGE,
156-
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', 'cockpituous-tasks'],
160+
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', f'cockpituous-tasks-{TEST_INSTANCE}'],
157161
volume_mounts=[
158162
BindMount('/run/secrets/webhook', host_path=config.webhook, flags=[VolumeFlag.READ_ONLY]),
159163
BindMount('/run/secrets/tasks', host_path=config.tasks, flags=[VolumeFlag.READ_ONLY]),
@@ -186,7 +190,7 @@ def pod(config: Config, pytestconfig) -> PodData:
186190
if have_webhook_container:
187191
containers.append(Container(
188192
url=TASKS_IMAGE,
189-
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', 'cockpituous-webhook'],
193+
extra_launch_args=[*COMMON_LAUNCH_ARGS, '--name', f'cockpituous-webhook-{TEST_INSTANCE}'],
190194
# that's what we want, but https://github.com/dcermak/pytest_container/issues/182
191195
# extra_entrypoint_args=['webhook'],
192196
volume_mounts=[
@@ -203,8 +207,9 @@ def pod(config: Config, pytestconfig) -> PodData:
203207
containers=containers,
204208
forwarded_ports=[
205209
# BUG: host_port= would be nice to make S3 log URLs work; but it has no effect:
206-
# https://github.com/dcermak/pytest_container/issues/190
207-
PortForwarding(container_port=9000, host_port=9000), # S3
210+
# https://github.com/dcermak/pytest_container/issues/190; but also, we want to keep the test
211+
# parallel-friendly
212+
PortForwarding(container_port=9000), # S3
208213
PortForwarding(container_port=9001), # minio console
209214
]
210215
)
@@ -215,7 +220,8 @@ def pod(config: Config, pytestconfig) -> PodData:
215220
for c in containers:
216221
c._is_local = True
217222

218-
with PodLauncher(pod_cockpituous, rootdir=pytestconfig.rootpath, pod_name='cockpituous') as launcher:
223+
with PodLauncher(pod_cockpituous, rootdir=pytestconfig.rootpath,
224+
pod_name=f'cockpituous-{TEST_INSTANCE}') as launcher:
219225
launcher.launch_pod()
220226

221227
# run minio in lieu of extra_entrypoint_args

0 commit comments

Comments
 (0)