|
| 1 | +# Cache Dependency Test Coverage |
| 2 | + |
| 3 | +This document describes how cache dependency resolution is tested across the test suite. |
| 4 | + |
| 5 | +## Dependency Patterns Tested |
| 6 | + |
| 7 | +### Chain Dependencies (A → B → C) |
| 8 | + |
| 9 | +When resource A embeds B, and B embeds C, purging C invalidates both B and A. |
| 10 | + |
| 11 | +``` |
| 12 | +LevelOne → LevelTwo → LevelThree |
| 13 | +purge(LevelThree) → LevelOne invalidated |
| 14 | +``` |
| 15 | + |
| 16 | +**Test:** `CacheDependencyTest::testDestroyByGrandChild` |
| 17 | + |
| 18 | +### Parent-Child Dependencies |
| 19 | + |
| 20 | +Purging a child invalidates its parent. |
| 21 | + |
| 22 | +``` |
| 23 | +LevelOne → LevelTwo |
| 24 | +purge(LevelTwo) → LevelOne invalidated |
| 25 | +``` |
| 26 | + |
| 27 | +**Test:** `CacheDependencyTest::testDestroyByChild` |
| 28 | + |
| 29 | +### Multiple Parents Depending on Same Child |
| 30 | + |
| 31 | +When multiple parents embed the same child, purging the child invalidates all parents. |
| 32 | + |
| 33 | +``` |
| 34 | +ParentA ──┐ |
| 35 | + ├──→ ChildC |
| 36 | +ParentB ──┘ |
| 37 | +purge(ChildC) → ParentA, ParentB both invalidated |
| 38 | +``` |
| 39 | + |
| 40 | +**Test:** `CacheDependencyTest::testMultipleParentsDependOnSameChild` |
| 41 | + |
| 42 | +### Unrelated Resources Independence |
| 43 | + |
| 44 | +Resources in separate dependency chains do not affect each other. |
| 45 | + |
| 46 | +``` |
| 47 | +Chain A: LevelOne → LevelTwo → LevelThree |
| 48 | +Chain B: ChildC (independent) |
| 49 | +purge(LevelThree) → LevelOne invalidated, ChildC unchanged |
| 50 | +``` |
| 51 | + |
| 52 | +**Test:** `CacheDependencyTest::testUnrelatedResourcesAreIndependent` |
| 53 | + |
| 54 | +### Embed-Based Dependencies with Donut Cache |
| 55 | + |
| 56 | +Blog posting embeds comment; purging comment invalidates blog posting. |
| 57 | + |
| 58 | +``` |
| 59 | +BlogPosting → Comment |
| 60 | +purge(Comment) → BlogPosting invalidated |
| 61 | +``` |
| 62 | + |
| 63 | +**Test:** `DonutRepositoryTest::testCacheDependency` |
| 64 | + |
| 65 | +### Tag-Based Invalidation |
| 66 | + |
| 67 | +Resources can be invalidated by their URI-derived tags. |
| 68 | + |
| 69 | +``` |
| 70 | +invalidateTags([uriTag('page://self/html/blog-posting')]) → BlogPosting invalidated |
| 71 | +``` |
| 72 | + |
| 73 | +**Test:** `DonutRepositoryTest::testInvalidateTags` |
| 74 | + |
| 75 | +## Component Unit Tests |
| 76 | + |
| 77 | +| Component | Test File | Coverage | |
| 78 | +|-----------|-----------|----------| |
| 79 | +| `UriTag::__invoke()` | `UtiTagTest::testInvoke` | URI to tag string conversion | |
| 80 | +| `UriTag::fromAssoc()` | `UtiTagTest::testFromAssoc` | Generate tags from array data | |
| 81 | +| `SurrogateKeys` | `SurrogateKeysTest` | Aggregate tags from multiple resources | |
| 82 | +| `RepositoryLogger` | `RepositoryLoggerTest` | Log formatting with arrays | |
| 83 | + |
| 84 | +## ETag Invalidation Verification |
| 85 | + |
| 86 | +All dependency tests verify both resource cache and ETag invalidation: |
| 87 | + |
| 88 | +| Test | ETag Assertions | |
| 89 | +|------|-----------------| |
| 90 | +| `testDestroyByChild` | Parent ETag invalidated | |
| 91 | +| `testDestroyByGrandChild` | All 3 levels' ETags invalidated | |
| 92 | +| `testUnrelatedResourcesAreIndependent` | Invalidated ETag gone, unrelated ETag preserved | |
| 93 | +| `testMultipleParentsDependOnSameChild` | Both parents' ETags invalidated | |
| 94 | + |
| 95 | +## Fake Resources for Testing |
| 96 | + |
| 97 | +Located in `tests/Fake/fake-app/src/Resource/Page/Dep/`: |
| 98 | + |
| 99 | +| Resource | Embeds | Purpose | |
| 100 | +|----------|--------|---------| |
| 101 | +| `LevelOne` | `LevelTwo` | Top of 3-level chain | |
| 102 | +| `LevelTwo` | `LevelThree` | Middle of chain | |
| 103 | +| `LevelThree` | - | Leaf node | |
| 104 | +| `ParentA` | `ChildC` | Multiple parent test | |
| 105 | +| `ParentB` | `ChildC` | Multiple parent test | |
| 106 | +| `ChildC` | - | Shared child resource | |
0 commit comments