feat: add Leader Election pattern#326
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results 1 files 1 suites 2m 49s ⏱️ Results for commit 874f457. ♻️ This comment has been updated with latest results. |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
There was a problem hiding this comment.
Pull request overview
Adds a new Leader Election pattern to PatternKit, including a fluent in-memory runtime, a Roslyn incremental source generator (plus public attributes), and a production-shaped warehouse demo wired into the example/pattern catalogs and documentation.
Changes:
- Introduces
LeaderElection<TContext>runtime with lease acquire/renew/expire/release semantics and result types. - Adds
[GenerateLeaderElection]+ callback attributes and aLeaderElectionGeneratorthat emits election/candidate factories with diagnostics. - Adds a “Warehouse Leader Election” example (DI + Generic Host hosted service) plus test and documentation/catalog wiring.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/Cloud/LeaderElection/LeaderElectionTests.cs | New TinyBDD coverage for acquire/renew/release, contention/expiry, and guard clauses. |
| test/PatternKit.Generators.Tests/LeaderElectionGeneratorTests.cs | Verifies generator output shape and diagnostic IDs for invalid declarations. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Adds coverage/assertions for new leader election attributes. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates expected catalog contents/counts to include Leader Election. |
| test/PatternKit.Examples.Tests/LeaderElectionDemo/WarehouseLeaderElectionDemoTests.cs | Validates fluent + generated demo, DI import, hosted service lifecycle, and catalog inclusion. |
| src/PatternKit.Generators/LeaderElection/LeaderElectionGenerator.cs | New incremental generator for typed leader election + candidate factory emission with diagnostics. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new analyzer diagnostic IDs PKLE001–PKLE004. |
| src/PatternKit.Generators.Abstractions/Cloud/LeaderElectionAttributes.cs | Adds public attributes consumed by the generator. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Adds Leader Election to the pattern coverage catalog (runtime/generator/example paths). |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Adds “Warehouse Leader Election” to the example catalog. |
| src/PatternKit.Examples/LeaderElectionDemo/WarehouseLeaderElectionDemo.cs | Implements warehouse leader election demo, generated host, and DI extension. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Wires the new example into aggregate AddPatternKitExamples() registration. |
| src/PatternKit.Core/Cloud/LeaderElection/LeaderElection.cs | New leader election runtime types (LeaderLease, results, candidate builder, election). |
| docs/patterns/toc.yml | Adds Leader Election to the patterns TOC. |
| docs/patterns/cloud/leader-election.md | New pattern documentation page with runtime usage snippet and guidance. |
| docs/guides/pattern-coverage.md | Updates coverage matrix to include Leader Election runtime + generator. |
| docs/generators/toc.yml | Adds Leader Election to generators TOC. |
| docs/generators/leader-election.md | New generator documentation page including diagnostics list. |
| docs/generators/index.md | Adds Leader Election to generator index table. |
| docs/examples/warehouse-leader-election.md | New example documentation page for the warehouse demo. |
| docs/examples/toc.yml | Adds Warehouse Leader Election to examples TOC. |
| docs/examples/index.md | Adds Warehouse Leader Election to the examples index list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "docs/examples/warehouse-leader-election.md", | ||
| "src/PatternKit.Examples/LeaderElectionDemo/WarehouseLeaderElectionDemo.cs", | ||
| "test/PatternKit.Examples.Tests/LeaderElectionDemo/WarehouseLeaderElectionDemoTests.cs", | ||
| ["fluent lease election", "generated candidate factory", "DI-importable Generic Host worker example"]), |
| private readonly Func<DateTimeOffset> _clock; | ||
| private readonly TimeSpan _leaseDuration; | ||
| private LeaderLease? _currentLease; | ||
|
|
||
| private LeaderElection(string name, TimeSpan leaseDuration, Func<DateTimeOffset>? clock) |
Code Coverage |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #326 +/- ##
==========================================
+ Coverage 89.75% 95.73% +5.97%
==========================================
Files 468 472 +4
Lines 38681 38987 +306
Branches 5524 5577 +53
==========================================
+ Hits 34718 37323 +2605
+ Misses 1777 1664 -113
+ Partials 2186 0 -2186
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Closes #321.
Validation
LeaderElectionGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseLeaderElectionGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseLeaderElectionGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseNote: the local full examples build still hits the existing analyzer/compiler mismatch (CS9057 with generated demo types); hosted CI validates the full examples/docs surface.