Skip to content

Commit b4d7b94

Browse files
heitorlessarubenfonseca
authored andcommitted
docs(maintainers): line editing, additional visuals to make it clearer
1 parent a800f81 commit b4d7b94

File tree

1 file changed

+74
-27
lines changed

1 file changed

+74
-27
lines changed

MAINTAINERS.md

+74-27
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
- [Structure](#structure)
3333
- [Mechanics](#mechanics)
3434
- [Authoring a new feature E2E test](#authoring-a-new-feature-e2e-test)
35+
- [1. Define infrastructure](#1-define-infrastructure)
36+
- [2. Deploy/Delete infrastructure when tests run](#2-deploydelete-infrastructure-when-tests-run)
37+
- [3. Access stack outputs for E2E tests](#3-access-stack-outputs-for-e2e-tests)
3538
- [Internals](#internals)
3639
- [Test runner parallelization](#test-runner-parallelization)
3740
- [CDK CLI parallelization](#cdk-cli-parallelization)
@@ -297,7 +300,7 @@ In the rare cases where both parties don't have the bandwidth or expertise to co
297300

298301
### Structure
299302

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).
301304

302305
**tests/e2e structure**
303306

@@ -338,17 +341,17 @@ Our E2E framework relies on pytest fixtures to coordinate infrastructure and tes
338341
Where:
339342

340343
- **`<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.
346349

347350
### Mechanics
348351

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.
350353

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.
352355

353356
> Class diagram to understand abstraction built when defining a new stack (`LoggerStack`)
354357
@@ -394,20 +397,23 @@ classDiagram
394397

395398
### Authoring a new feature E2E test
396399

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:
398401

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.
402+
```mermaid
403+
graph LR
404+
A["1. Define infrastructure"]-->B["2. Deploy/Delete infrastructure"]-->C["3.Access Stack outputs" ]
405+
```
400406

401-
**Define infrastructure**
407+
#### 1. Define infrastructure
402408

403-
We use CDK as our Infrastructure as Code tool of choice. Before you start using CDK, you need to take the following steps:
409+
We use CDK as our Infrastructure as Code tool of choice. Before you start using CDK, you'd take the following steps:
404410

405411
1. Create `tests/e2e/event_handler/infrastructure.py` file
406412
2. Create a new class `EventHandlerStack` and inherit from `BaseInfrastructure`
407413
3. Override `create_resources` method and define your infrastructure using CDK
408414
4. (Optional) Create a Lambda function under `handlers/alb_handler.py`
409415

410-
> Excerpt `infrastructure.py` for Event Handler
416+
> Excerpt `tests/e2e/event_handler/infrastructure.py`
411417
412418
```python
413419
class EventHandlerStack(BaseInfrastructure):
@@ -430,7 +436,7 @@ class EventHandlerStack(BaseInfrastructure):
430436
...
431437
```
432438

433-
> Excerpt `alb_handler.py` for Event Handler
439+
> Excerpt `tests/e2e/event_handler/handlers/alb_handler.py`
434440
435441
```python
436442
from aws_lambda_powertools.event_handler import ALBResolver, Response, content_types
@@ -453,11 +459,11 @@ def lambda_handler(event, context):
453459
return app.resolve(event, context)
454460
```
455461

456-
**Deploy/Delete infrastructure when tests run**
462+
#### 2. Deploy/Delete infrastructure when tests run
457463

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`.
459465

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.
461467

462468
> Excerpt `conftest.py` for Event Handler
463469
@@ -484,11 +490,13 @@ def infrastructure():
484490

485491
```
486492

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`.
488496

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.
490498

491-
> Excerpt `test_header_serializer.py` for Event Handler
499+
> Excerpt `tests/e2e/event_handler/test_header_serializer.py`
492500
493501
```python
494502
@pytest.fixture
@@ -508,7 +516,9 @@ def test_alb_headers_serializer(alb_basic_listener_endpoint):
508516

509517
#### Test runner parallelization
510518

511-
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:
512522

513523
```mermaid
514524
graph TD
@@ -541,9 +551,20 @@ graph TD
541551

542552
#### CDK CLI parallelization
543553

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.
555+
556+
```mermaid
557+
flowchart TD
558+
subgraph "Deploying distinct CDK Apps"
559+
EventHandlerInfra["Event Handler CDK App"] --> EventHandlerSynth
560+
TracerInfra["Tracer CDK App"] --> TracerSynth
561+
EventHandlerSynth["cdk synth --out cdk.out/event_handler"] --> EventHandlerDeploy["cdk deploy --app cdk.out/event_handler"]
562+
563+
TracerSynth["cdk synth --out cdk.out/tracer"] --> TracerDeploy["cdk deploy --app cdk.out/tracer"]
564+
end
565+
```
545566

546-
We also create a typical CDK `app.py` at runtime with the information we know for a given feature when tests run on a per Python version basis.
567+
We create the typical CDK `app.py` at runtime when tests run, since we know which feature and Python version we're dealing with (locally or at CI).
547568

548569
> Excerpt `cdk_app_V39.py` for Event Handler created at deploy phase
549570
@@ -554,7 +575,7 @@ stack.create_resources()
554575
stack.app.synth()
555576
```
556577

557-
When E2E tests are run for a single feature or all of them, `cdk.out` looks like the following:
578+
When we run E2E tests for a single feature or all of them, our `cdk.out` looks like this:
558579

559580
```shell
560581
total 8
@@ -566,10 +587,36 @@ drwxr-xr-x 18 lessa staff 576B Sep 6 15:38 metrics
566587
drwxr-xr-x 22 lessa staff 704B Sep 9 10:52 tracer
567588
```
568589

590+
```mermaid
591+
classDiagram
592+
class CdkOutDirectory {
593+
feature_name/
594+
layer_build/
595+
layer_build.diff
596+
}
597+
598+
class EventHandler {
599+
manifest.json
600+
stack_outputs.json
601+
cdk_app_V39.py
602+
asset.uuid/
603+
...
604+
}
605+
606+
class StackOutputsJson {
607+
BasicHandlerArn: str
608+
ALBDnsName: str
609+
...
610+
}
611+
612+
CdkOutDirectory <|-- EventHandler : feature_name/
613+
StackOutputsJson <|-- EventHandler
614+
```
615+
569616
Where:
570617

571-
- `<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
574621

575622
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

Comments
 (0)