Skip to content

Commit d66cf98

Browse files
committed
fix: make sure multiple e2e tests run concurrently
1 parent 26a630f commit d66cf98

File tree

9 files changed

+54
-13
lines changed

9 files changed

+54
-13
lines changed

tests/e2e/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def lambda_layer_build(tmp_path_factory: pytest.TempPathFactory, worker_id: str)
2323

2424
layer = LocalLambdaPowertoolsLayer()
2525
yield from call_once(
26+
id="lambda_layer",
2627
task=layer.build,
2728
tmp_path_factory=tmp_path_factory,
2829
worker_id=worker_id,

tests/e2e/event_handler/conftest.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import pytest
22

33
from tests.e2e.event_handler.infrastructure import EventHandlerStack
4+
from tests.e2e.utils.infrastructure import call_once
45

56

67
@pytest.fixture(autouse=True, scope="module")
7-
def infrastructure():
8+
def infrastructure(tmp_path_factory: pytest.TempPathFactory, worker_id: str):
89
"""Setup and teardown logic for E2E test infrastructure
910
1011
Yields
@@ -14,6 +15,10 @@ def infrastructure():
1415
"""
1516
stack = EventHandlerStack()
1617
try:
17-
yield stack.deploy()
18+
return (
19+
yield from call_once(
20+
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21+
)
22+
)
1823
finally:
1924
stack.delete()

tests/e2e/idempotency/conftest.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import pytest
22

33
from tests.e2e.idempotency.infrastructure import IdempotencyDynamoDBStack
4+
from tests.e2e.utils.infrastructure import call_once
45

56

67
@pytest.fixture(autouse=True, scope="module")
7-
def infrastructure(tmp_path_factory, worker_id):
8+
def infrastructure(tmp_path_factory: pytest.TempPathFactory, worker_id: str):
89
"""Setup and teardown logic for E2E test infrastructure
910
1011
Yields
@@ -14,6 +15,10 @@ def infrastructure(tmp_path_factory, worker_id):
1415
"""
1516
stack = IdempotencyDynamoDBStack()
1617
try:
17-
yield stack.deploy()
18+
return (
19+
yield from call_once(
20+
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21+
)
22+
)
1823
finally:
1924
stack.delete()

tests/e2e/logger/conftest.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from tests.e2e.logger.infrastructure import LoggerStack
4+
from tests.e2e.utils.infrastructure import call_once
45

56

67
@pytest.fixture(autouse=True, scope="module")
@@ -14,6 +15,13 @@ def infrastructure(tmp_path_factory, worker_id):
1415
"""
1516
stack = LoggerStack()
1617
try:
17-
yield stack.deploy()
18+
return (
19+
yield from call_once(
20+
job_id=stack.feature_name,
21+
task=stack.deploy,
22+
tmp_path_factory=tmp_path_factory,
23+
worker_id=worker_id,
24+
)
25+
)
1826
finally:
1927
stack.delete()

tests/e2e/metrics/conftest.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from tests.e2e.metrics.infrastructure import MetricsStack
4+
from tests.e2e.utils.infrastructure import call_once
45

56

67
@pytest.fixture(autouse=True, scope="module")
@@ -14,6 +15,10 @@ def infrastructure(tmp_path_factory, worker_id):
1415
"""
1516
stack = MetricsStack()
1617
try:
17-
yield stack.deploy()
18+
return (
19+
yield from call_once(
20+
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21+
)
22+
)
1823
finally:
1924
stack.delete()

tests/e2e/parameters/conftest.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from tests.e2e.parameters.infrastructure import ParametersStack
4+
from tests.e2e.utils.infrastructure import call_once
45

56

67
@pytest.fixture(autouse=True, scope="module")
@@ -14,6 +15,10 @@ def infrastructure(tmp_path_factory, worker_id):
1415
"""
1516
stack = ParametersStack()
1617
try:
17-
yield stack.deploy()
18+
return (
19+
yield from call_once(
20+
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21+
)
22+
)
1823
finally:
1924
stack.delete()

tests/e2e/streaming/conftest.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from tests.e2e.streaming.infrastructure import StreamingStack
4+
from tests.e2e.utils.infrastructure import call_once
45

56

67
@pytest.fixture(autouse=True, scope="module")
@@ -14,6 +15,10 @@ def infrastructure(tmp_path_factory, worker_id):
1415
"""
1516
stack = StreamingStack()
1617
try:
17-
yield stack.deploy()
18+
return (
19+
yield from call_once(
20+
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
21+
)
22+
)
1823
finally:
1924
stack.delete()

tests/e2e/tracer/conftest.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import pytest
22

33
from tests.e2e.tracer.infrastructure import TracerStack
4+
from tests.e2e.utils.infrastructure import call_once
45

56

67
@pytest.fixture(autouse=True, scope="module")
7-
def infrastructure():
8+
def infrastructure(tmp_path_factory, worker_id):
89
"""Setup and teardown logic for E2E test infrastructure
910
1011
@@ -15,6 +16,10 @@ def infrastructure():
1516
"""
1617
stack = TracerStack()
1718
try:
18-
yield stack.deploy()
19+
return (
20+
yield from call_once(
21+
job_id=stack.feature_name, task=stack.deploy, tmp_path_factory=tmp_path_factory, worker_id=worker_id
22+
)
23+
)
1924
finally:
2025
stack.delete()

tests/e2e/utils/infrastructure.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import logging
33
import os
4-
import platform
54
import subprocess
65
import sys
76
import textwrap
@@ -57,7 +56,7 @@ def __init__(self) -> None:
5756
self._feature_infra_module_path = self.feature_path / "infrastructure"
5857
self._feature_infra_file = self.feature_path / "infrastructure.py"
5958
self._handlers_dir = self.feature_path / "handlers"
60-
self._cdk_out_dir: Path = CDK_OUT_PATH / "-".join(platform.python_version_tuple()) / self.feature_name
59+
self._cdk_out_dir: Path = CDK_OUT_PATH / self.feature_name
6160
self._stack_outputs_file = f'{self._cdk_out_dir / "stack_outputs.json"}'
6261

6362
if not self._feature_infra_file.exists():
@@ -287,6 +286,7 @@ def add_cfn_output(self, name: str, value: str, arn: str = ""):
287286

288287

289288
def call_once(
289+
job_id: str,
290290
task: Callable,
291291
tmp_path_factory: pytest.TempPathFactory,
292292
worker_id: str,
@@ -296,6 +296,8 @@ def call_once(
296296
297297
Parameters
298298
----------
299+
id : str
300+
Random string that uniquely identifies this call
299301
task : Callable
300302
Function to call once and JSON serialize result whether parallel test is enabled or not.
301303
tmp_path_factory : pytest.TempPathFactory
@@ -318,7 +320,7 @@ def call_once(
318320
else:
319321
# tmp dir shared by all workers
320322
root_tmp_dir = tmp_path_factory.getbasetemp().parent
321-
cache = root_tmp_dir / f"{PYTHON_RUNTIME_VERSION}_cache.json"
323+
cache = root_tmp_dir / f"{PYTHON_RUNTIME_VERSION}_{job_id}_cache.json"
322324

323325
with FileLock(f"{cache}.lock"):
324326
# If cache exists, return task outputs back

0 commit comments

Comments
 (0)