Skip to main content

adk_kernel/conformance/charter/
mod.rs

1//! Conformance suites for the charter module's stores (spec 3.5 §7.10, §7.11, §11;
2//! features `charter` and `conformance`).
3//!
4//! | Store | Harness | Test macro | Cases |
5//! |-------|---------|------------|-------|
6//! | [`CharterStore`](crate::charter::CharterStore) | [`CharterStoreHarness`] | [`charter_store_conformance_tests!`](crate::charter_store_conformance_tests) | [`charter_store`] |
7//! | [`KpiStore`](crate::charter::KpiStore) | [`KpiStoreHarness`] | [`kpi_store_conformance_tests!`](crate::kpi_store_conformance_tests) | [`kpi_store`] |
8//! | [`AutonomyStore`](crate::charter::AutonomyStore) | [`AutonomyStoreHarness`] | [`autonomy_store_conformance_tests!`](crate::autonomy_store_conformance_tests) | [`autonomy_store`] |
9//! | [`SignalStore`](crate::charter::SignalStore) | [`SignalStoreHarness`] | [`signal_store_conformance_tests!`](crate::signal_store_conformance_tests) | [`signal_store`] |
10//!
11//! A harness opens the backend; each `open` returns a new handle over the same data, as a
12//! restarted or second replica would see it. Every case writes under fresh sites, jobs,
13//! partitions and sources, so a harness may point every case at one shared database. The
14//! macros are used as [`process_store_conformance_tests!`](crate::process_store_conformance_tests)
15//! is; see the [conformance module](crate::conformance).
16//!
17//! # Example
18//!
19//! ```rust,ignore
20//! use std::sync::Arc;
21//! use adk_kernel::charter::{CharterStore, InMemoryCharterStore};
22//! use adk_kernel::conformance::charter::CharterStoreHarness;
23//!
24//! struct InMemory;
25//!
26//! #[async_trait::async_trait]
27//! impl CharterStoreHarness for InMemory {
28//!     async fn open(&self) -> Arc<dyn CharterStore> {
29//!         Arc::new(InMemoryCharterStore::new())
30//!     }
31//!
32//!     fn is_durable(&self) -> bool {
33//!         false
34//!     }
35//! }
36//!
37//! adk_kernel::charter_store_conformance_tests! { harness = InMemory }
38//! ```
39
40pub mod autonomy_store;
41pub mod charter_store;
42pub mod fixtures;
43pub mod kpi_store;
44pub mod signal_store;
45
46pub use autonomy_store::AutonomyStoreHarness;
47pub use charter_store::CharterStoreHarness;
48pub use kpi_store::KpiStoreHarness;
49pub use signal_store::SignalStoreHarness;
50
51/// Generates one test per [`charter_store`] case for a [`CharterStoreHarness`] (spec 3.5
52/// §7.11, §11).
53#[macro_export]
54macro_rules! charter_store_conformance_tests {
55    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
56        $(#[$attr])*
57        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
58        async fn charter_store_empty_site() {
59            $crate::conformance::charter::charter_store::empty_site(&$harness).await;
60        }
61        $(#[$attr])*
62        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
63        async fn charter_store_commit_reads_back() {
64            $crate::conformance::charter::charter_store::commit_reads_back(&$harness).await;
65        }
66        $(#[$attr])*
67        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
68        async fn charter_store_versions_increment() {
69            $crate::conformance::charter::charter_store::versions_increment(&$harness).await;
70        }
71        $(#[$attr])*
72        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
73        async fn charter_store_append_refuses_gaps_and_repeats() {
74            $crate::conformance::charter::charter_store::append_refuses_gaps_and_repeats(&$harness)
75                .await;
76        }
77        $(#[$attr])*
78        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
79        async fn charter_store_commit_refuses_an_invalid_draft() {
80            $crate::conformance::charter::charter_store::commit_refuses_an_invalid_draft(&$harness)
81                .await;
82        }
83        $(#[$attr])*
84        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
85        async fn charter_store_commit_refuses_an_unsatisfied_chain() {
86            $crate::conformance::charter::charter_store::commit_refuses_an_unsatisfied_chain(
87                &$harness,
88            )
89            .await;
90        }
91        $(#[$attr])*
92        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
93        async fn charter_store_the_charter_in_force_governs_a_change() {
94            $crate::conformance::charter::charter_store::the_charter_in_force_governs_a_change(
95                &$harness,
96            )
97            .await;
98        }
99        $(#[$attr])*
100        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
101        async fn charter_store_concurrent_commits_take_one_version_each() {
102            $crate::conformance::charter::charter_store::concurrent_commits_take_one_version_each(
103                &$harness,
104            )
105            .await;
106        }
107        $(#[$attr])*
108        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
109        async fn charter_store_versions_survive_a_restart() {
110            $crate::conformance::charter::charter_store::versions_survive_a_restart(&$harness)
111                .await;
112        }
113    };
114}
115
116/// Generates one test per [`kpi_store`] case for a [`KpiStoreHarness`] (spec 3.5 §7.11,
117/// §11).
118#[macro_export]
119macro_rules! kpi_store_conformance_tests {
120    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
121        $(#[$attr])*
122        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
123        async fn kpi_store_samples_round_trip_in_order() {
124            $crate::conformance::charter::kpi_store::samples_round_trip_in_order(&$harness).await;
125        }
126        $(#[$attr])*
127        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
128        async fn kpi_store_one_sample_per_instant() {
129            $crate::conformance::charter::kpi_store::one_sample_per_instant(&$harness).await;
130        }
131        $(#[$attr])*
132        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
133        async fn kpi_store_refuses_a_value_that_is_not_finite() {
134            $crate::conformance::charter::kpi_store::refuses_a_value_that_is_not_finite(&$harness)
135                .await;
136        }
137        $(#[$attr])*
138        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
139        async fn kpi_store_aggregates_have_no_gaps() {
140            $crate::conformance::charter::kpi_store::aggregates_have_no_gaps(&$harness).await;
141        }
142        $(#[$attr])*
143        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
144        async fn kpi_store_states_round_trip() {
145            $crate::conformance::charter::kpi_store::states_round_trip(&$harness).await;
146        }
147        $(#[$attr])*
148        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
149        async fn kpi_store_concurrent_records_keep_one_per_instant() {
150            $crate::conformance::charter::kpi_store::concurrent_records_keep_one_per_instant(
151                &$harness,
152            )
153            .await;
154        }
155        $(#[$attr])*
156        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
157        async fn kpi_store_samples_survive_a_restart() {
158            $crate::conformance::charter::kpi_store::samples_survive_a_restart(&$harness).await;
159        }
160    };
161}
162
163/// Generates one test per [`autonomy_store`] case for an [`AutonomyStoreHarness`] (spec 3.5
164/// §7.11, §11).
165#[macro_export]
166macro_rules! autonomy_store_conformance_tests {
167    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
168        $(#[$attr])*
169        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
170        async fn autonomy_store_unknown_job() {
171            $crate::conformance::charter::autonomy_store::unknown_job(&$harness).await;
172        }
173        $(#[$attr])*
174        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
175        async fn autonomy_store_apply_registers_then_moves() {
176            $crate::conformance::charter::autonomy_store::apply_registers_then_moves(&$harness)
177                .await;
178        }
179        $(#[$attr])*
180        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
181        async fn autonomy_store_apply_refuses_other_revisions() {
182            $crate::conformance::charter::autonomy_store::apply_refuses_other_revisions(&$harness)
183                .await;
184        }
185        $(#[$attr])*
186        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
187        async fn autonomy_store_apply_refuses_a_mismatched_change() {
188            $crate::conformance::charter::autonomy_store::apply_refuses_a_mismatched_change(
189                &$harness,
190            )
191            .await;
192        }
193        $(#[$attr])*
194        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
195        async fn autonomy_store_decisions_once_and_in_order() {
196            $crate::conformance::charter::autonomy_store::decisions_once_and_in_order(&$harness)
197                .await;
198        }
199        $(#[$attr])*
200        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
201        async fn autonomy_store_concurrent_applies_move_once() {
202            $crate::conformance::charter::autonomy_store::concurrent_applies_move_once(&$harness)
203                .await;
204        }
205        $(#[$attr])*
206        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
207        async fn autonomy_store_records_survive_a_restart() {
208            $crate::conformance::charter::autonomy_store::records_survive_a_restart(&$harness)
209                .await;
210        }
211    };
212}
213
214/// Generates one test per [`signal_store`] case for a [`SignalStoreHarness`] (spec 3.5
215/// §7.10, §11).
216#[macro_export]
217macro_rules! signal_store_conformance_tests {
218    ($(#[$attr:meta])* harness = $harness:expr $(,)?) => {
219        $(#[$attr])*
220        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
221        async fn signal_store_first_opens_then_counts() {
222            $crate::conformance::charter::signal_store::first_opens_then_counts(&$harness).await;
223        }
224        $(#[$attr])*
225        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
226        async fn signal_store_keys_are_apart() {
227            $crate::conformance::charter::signal_store::keys_are_apart(&$harness).await;
228        }
229        $(#[$attr])*
230        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
231        async fn signal_store_close_then_reopen() {
232            $crate::conformance::charter::signal_store::close_then_reopen(&$harness).await;
233        }
234        $(#[$attr])*
235        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
236        async fn signal_store_list_filters_and_orders() {
237            $crate::conformance::charter::signal_store::list_filters_and_orders(&$harness).await;
238        }
239        $(#[$attr])*
240        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
241        async fn signal_store_hits_count_per_source_and_window() {
242            $crate::conformance::charter::signal_store::hits_count_per_source_and_window(&$harness)
243                .await;
244        }
245        $(#[$attr])*
246        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
247        async fn signal_store_concurrent_records_count_every_signal() {
248            $crate::conformance::charter::signal_store::concurrent_records_count_every_signal(
249                &$harness,
250            )
251            .await;
252        }
253        $(#[$attr])*
254        #[::tokio::test(flavor = "multi_thread", worker_threads = 4)]
255        async fn signal_store_records_survive_a_restart() {
256            $crate::conformance::charter::signal_store::records_survive_a_restart(&$harness).await;
257        }
258    };
259}