You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -297,7 +300,7 @@ In the rare cases where both parties don't have the bandwidth or expertise to co
297
300
298
301
### Structure
299
302
300
-
Our E2E framework relies on pytest fixtures to coordinate infrastructure and test parallelization - see [Test Parallelization](#test-runner-parallelization) and [CDK CLI Parallelization](#cdk-cli-parallelization).
303
+
Our E2E framework relies on [Pytest fixtures](https://docs.pytest.org/en/6.2.x/fixture.html) to coordinate infrastructure and test parallelization - see [Test Parallelization](#test-runner-parallelization) and [CDK CLI Parallelization](#cdk-cli-parallelization).
301
304
302
305
**tests/e2e structure**
303
306
@@ -338,17 +341,17 @@ Our E2E framework relies on pytest fixtures to coordinate infrastructure and tes
338
341
Where:
339
342
340
343
-**`<feature>/infrastructure.py`**. Uses CDK to define the infrastructure a given feature needs.
341
-
-**`<feature>/handlers/`**. Lambda function handlers that will be automatically deployed and exported in PascalCase (e.g., `BasicHandler`) for later use.
342
-
-**`util/>`**. Test utilities to build data and fetch AWS data to ease assertion
343
-
-**`conftest.py`**. Handles deployment and deletion a given feature Infrastructure. Hierarchy matters:
344
-
- Top-level `e2e/conftest` deploys stacks only once and blocks I/O across all CPUs.
345
-
- Feature-level `e2e/<feature>/conftest` deploys stacks in parallel and make them independent of each other.
344
+
-**`<feature>/handlers/`**. Lambda function handlers to build, deploy, and exposed as stack output in PascalCase (e.g., `BasicHandler`).
345
+
-**`utils/`**. Test utilities to build data and fetch AWS data to ease assertion
346
+
-**`conftest.py`**. Deploys and deletes a given feature infrastructure. Hierarchy matters:
347
+
-**Top-level (`e2e/conftest`)**. Builds Lambda Layer only once and blocks I/O across all CPU workers.
348
+
-**Feature-level (`e2e/<feature>/conftest`)**. Deploys stacks in parallel and make them independent of each other.
346
349
347
350
### Mechanics
348
351
349
-
Under [`BaseInfrastructure`](https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/tests/e2e/utils/infrastructure.py), we hide the complexity of deployment/delete coordination under `deploy`, `delete`, and `create_lambda_functions` methods.
352
+
Under [`BaseInfrastructure`](https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/tests/e2e/utils/infrastructure.py), we hide the complexity of deployment and delete coordination under `deploy`, `delete`, and `create_lambda_functions` methods.
350
353
351
-
This allows us to benefit from test and deployment parallelization, use IDE step-through debugging for a single test, run a subset of tests and only deploy their related infrastructure, without any custom configuration.
354
+
This allows us to benefit from test and deployment parallelization, use IDE step-through debugging for a single test, run one, subset, or all tests and only deploy their related infrastructure, without any custom configuration.
352
355
353
356
> Class diagram to understand abstraction built when defining a new stack (`LoggerStack`)
354
357
@@ -394,20 +397,23 @@ classDiagram
394
397
395
398
### Authoring a new feature E2E test
396
399
397
-
Imagine you're going to create E2E for Event Handler feature for the first time.
400
+
Imagine you're going to create E2E for Event Handler feature for the first time. Keep the following mental model when reading:
398
401
399
-
As a mental model, you'll need to: **(1)** Define infrastructure, **(2)** Deploy/Delete infrastructure when tests run, and **(3)** Expose resources for E2E tests.
#### 2. Deploy/Delete infrastructure when tests run
457
463
458
-
We need to instruct Pytest to deploy our infrastructure when our tests start, and delete it when they complete (successfully or not).
464
+
We need to create a Pytest fixture for our new feature under `tests/e2e/event_handler/conftest.py`.
459
465
460
-
For this, we create a `test/e2e/event_handler/conftest.py`and create fixture scoped to our test module. This will remain static and will not need any further modification in the future.
466
+
This will instruct Pytest to deploy our infrastructure when our tests start, and delete it when they complete whether tests are successful or not. Note that this file will not need any modification in the future.
461
467
462
468
> Excerpt `conftest.py` for Event Handler
463
469
@@ -484,11 +490,13 @@ def infrastructure():
484
490
485
491
```
486
492
487
-
**Expose resources for E2E tests**
493
+
#### 3. Access stack outputs for E2E tests
494
+
495
+
Within our tests, we should now have access to the `infrastructure` fixture we defined earlier in `tests/e2e/event_handler/conftest.py`.
488
496
489
-
Within our tests, we should now have access to the `infrastructure` fixture we defined. We can access any Stack Output using pytest dependency injection.
497
+
We can access any Stack Output using pytest dependency injection.
490
498
491
-
> Excerpt `test_header_serializer.py` for Event Handler
We parallelize our end-to-end tests to benefit from speed and isolate Lambda functions to ease asserting side effects (e.g., traces, logs, etc.). The following diagram demonstrates the process we take every time you use `make e2e`:
519
+
Besides speed, we parallelize our end-to-end tests to ease asserting async side-effects may take a while per test too, _e.g., traces to become available_.
520
+
521
+
The following diagram demonstrates the process we take every time you use `make e2e` locally or at CI:
512
522
513
523
```mermaid
514
524
graph TD
@@ -541,9 +551,20 @@ graph TD
541
551
542
552
#### CDK CLI parallelization
543
553
544
-
For CDK CLI to work with [independent CDK Apps](https://docs.aws.amazon.com/cdk/v2/guide/apps.html), we specify an output directory when running `cdk synth -o cdk.out/<feature>` and then deploy from that said output directory with `cdk deploy --app cdk.out/<feature>`.
554
+
For CDK CLI to work with [independent CDK Apps](https://docs.aws.amazon.com/cdk/v2/guide/apps.html), we specify an output directory when synthesizing our stack and deploy from said output directory.
-`<feature>` has CDK Assets, CDK `manifest.json`, our `cdk_app_<PyVersion>.py` and `stack_outputs.json`
572
-
-`layer_build` contains our Lambda Layer source code built once, used by all stacks independently
573
-
-`layer_build.diff` contains a hash on whether our source code has changed to speed up further deployments and E2E tests
618
+
-**`<feature>`**. Contains CDK Assets, CDK `manifest.json`, our `cdk_app_<PyVersion>.py` and `stack_outputs.json`
619
+
-**`layer_build`**. Contains our Lambda Layer source code built once, used by all stacks independently
620
+
-**`layer_build.diff`**. Contains a hash on whether our source code has changed to speed up further deployments and E2E tests
574
621
575
622
Together, all of this allows us to use Pytest like we would for any project, use CDK CLI and its [context methods](https://docs.aws.amazon.com/cdk/v2/guide/context.html#context_methods) (`from_lookup`), and use step-through debugging for a single E2E test without any extra configuration.
0 commit comments