Files
alkstore/alkstore-sqlite/tests/contract_suite.rs
T
glm-5.3-flash 360e71e51e Contract-suite tx commit-atomicity rows (task suite-tx-commit-atomicity-rows): the N-5 panic-probe admission in properties.rs's module doc (spawned with_tx task joined via JoinError::is_panic — catch_unwind around an async closure cannot see the panic point across an await; post-panic assertions read-only until convergence, single-task drive, no race window; ADR-017 §2 class 4) and three version-stamped rows: outbox_enqueue_tx_commit_atomicity (rollback drops the backing-queue job with the business write — get_job_tx-gone + run_once claims nothing; commit makes the job claimable exactly when the business write commits, real delivery through the RecordingDelivery closure with job-id identity, derived __alkstore_outbox:mail queue, exact payload, 60/5/5 stamps, consumed-after-ack; ADR-014 §1, ADR-010 §3a, ADR-021 §4, ADR-007), publish_with_key_tx_commit_atomicity (rollback drops the keyed event with the business write, key round-tripping inside the tx; commit surfaces it to read_since and a post-commit subscriber attach with the key round-tripping; ADR-015 §2/§4, ADR-021 §4, ADR-007), and with_tx_panicking_closure_rolls_back (N-5's probe against real engines: the panicking closure writes all four kinds then panics mid-flight; panic surfaces via the join; no-ghost reads converge with begin_tx granting every iteration; pre-panic listener silence on the notified channel; ghost never claimable; fresh with_tx commits through the same seam — both engines green; ADR-007, ADR-021 §4) — wired into both engines' suite targets (SQLite tokio tests, pg harness_row!s). Dispositions recorded in Notes: the 60/5/5 stamp inspection rides the delivery handle's job() because get_job cannot target the reserved derived backing queue through the contract surface (exemplar row pins the rejection; engine-side raw-row probes stayed put), the panic row's notify leg is a windowed silence (SQLite's wake overtriggers on any commit — the fully cross-engine notify-ghost pin rides the engines' rollback-ghosts twins, the suite's drop-rollback row made the same call), the closure tail routes through a #[cold] mid_flight_panic -> Error helper (a bare Err(panic!()) tail trips unreachable_code under -D warnings), and the post-panic convergence loop is the suite-side bounded wait (state outcomes only, begin_tx doubling as the seam-still-grants probe). Verified: sqlite suite 19/19, pg suite 19/19 vs harness twice (postgres/poc@:15432) + solo re-runs of each new row per engine (determinism), workspace build/test green, clippy -D warnings, fmt clean
2026-10-10 06:17:18 +00:00

202 lines
7.2 KiB
Rust

//! The suite-driving test target: the SQLite engine's backlog column
//! (ADR-022's option (a) — the rows live in `alkstore-contract-suite`,
//! this target is the executor that runs them against the SQLite
//! factory; wave 5 runs the same rows against pg's).
//!
//! The factory: a fresh temp file under a fresh instance directory per
//! `open` (every call gets its own never-before-used path — the
//! isolation guarantee), teardown deleting the directory (idempotent —
//! already-deleted is already-torn-down, `Ok`). Close-arm rows drop
//! the store handle (the dispose carrier) — deleting files under a
//! live store is not a close mechanism.
use std::path::PathBuf;
use std::sync::atomic::{AtomicU64, Ordering};
use alkstore::{BoxedFuture, Error, Result, Store};
use alkstore_contract_suite::StoreFactory;
use alkstore_sqlite::open;
/// The SQLite suite factory: fresh temp-file store per `open`,
/// idempotent directory-delete teardown. `Send + Sync` — instance
/// state is a path prefix and a counter.
struct SqliteFactory {
dir: PathBuf,
instance: AtomicU64,
}
impl SqliteFactory {
fn new(tag: &str) -> Self {
let dir = std::env::temp_dir().join(format!(
"alkstore-suite-{tag}-{}-{:?}",
std::process::id(),
std::thread::current().id()
));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
SqliteFactory {
dir,
instance: AtomicU64::new(0),
}
}
}
impl StoreFactory for SqliteFactory {
fn open(&self) -> BoxedFuture<'_, Result<Box<dyn Store>>> {
let n = self.instance.fetch_add(1, Ordering::SeqCst);
let path = self
.dir
.join(format!("store-{n}.db"))
.to_str()
.unwrap_or_default()
.to_string();
Box::pin(async move { open(&path, Default::default()) })
}
fn teardown(&self) -> BoxedFuture<'_, Result<()>> {
let dir = self.dir.clone();
Box::pin(async move {
match std::fs::remove_dir_all(&dir) {
Ok(()) => Ok(()),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(()),
Err(e) => Err(Error::database(e)),
}
})
}
}
mod rows {
use alkstore_contract_suite::properties::{
drop_rollback_leaves_no_ghosts, duration_refusal_on_non_positive_ttl,
enqueue_opts_resolution, extent_clamp_semantics, in_tx_reads_see_own_writes,
job_handle_validity_predicate, name_validation_rejects_empty_and_reserved,
outbox_enqueue_tx_commit_atomicity, payload_round_trip_stores_exact_encoding,
payload_too_large_never_produced_on_sqlite, publish_with_key_tx_commit_atomicity,
queue_depth_reclaim_and_dead_letter, receiver_close_and_save_arms,
scheduler_boundary_fires, scheduler_bounded_catchup, scheduler_leadership_discipline,
sweep_no_stranded_rows, with_tx_panicking_closure_rolls_back,
};
use super::SqliteFactory;
fn factory(tag: &str) -> SqliteFactory {
SqliteFactory::new(tag)
}
#[tokio::test(flavor = "multi_thread")]
async fn row_name_validation_rejects_empty_and_reserved() {
name_validation_rejects_empty_and_reserved(&factory("row-name-validation")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_extent_clamp_semantics() {
extent_clamp_semantics(&factory("row-extent-clamp")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_duration_refusal_on_non_positive_ttl() {
duration_refusal_on_non_positive_ttl(&factory("row-duration-refusal")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_payload_round_trip_stores_exact_encoding() {
payload_round_trip_stores_exact_encoding(&factory("row-payload-round-trip")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_payload_too_large_never_produced_on_sqlite() {
payload_too_large_never_produced_on_sqlite(&factory("row-no-too-large")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_drop_rollback_leaves_no_ghosts() {
drop_rollback_leaves_no_ghosts(&factory("row-drop-rollback")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_in_tx_reads_see_own_writes() {
in_tx_reads_see_own_writes(&factory("row-in-tx-ryow")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_enqueue_opts_resolution() {
enqueue_opts_resolution(&factory("row-opts-resolution")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_receiver_close_and_save_arms() {
receiver_close_and_save_arms(&factory("row-receiver-arms")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_job_handle_validity_predicate() {
job_handle_validity_predicate(&factory("row-handle-predicate")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_queue_depth_reclaim_and_dead_letter() {
queue_depth_reclaim_and_dead_letter(&factory("row-queue-depth")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_sweep_no_stranded_rows() {
sweep_no_stranded_rows(&factory("row-sweep-stranded")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_scheduler_boundary_fires() {
scheduler_boundary_fires(&factory("row-scheduler-boundary")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_scheduler_bounded_catchup() {
scheduler_bounded_catchup(&factory("row-scheduler-catchup")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_scheduler_leadership_discipline() {
scheduler_leadership_discipline(&factory("row-scheduler-leadership")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_outbox_enqueue_tx_commit_atomicity() {
outbox_enqueue_tx_commit_atomicity(&factory("row-outbox-tx-atomicity")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_publish_with_key_tx_commit_atomicity() {
publish_with_key_tx_commit_atomicity(&factory("row-keyed-tx-atomicity")).await;
}
#[tokio::test(flavor = "multi_thread")]
async fn row_with_tx_panicking_closure_rolls_back() {
with_tx_panicking_closure_rolls_back(&factory("row-panic-rollback")).await;
}
}
mod factory_shape {
use super::SqliteFactory;
use alkstore_contract_suite::StoreFactory;
/// ADR-022's factory contract: every open yield is isolated (no two
/// opens share rows) and teardown is idempotent per instance; a
/// failing assertion early-exit (the panic path) leaves teardown
/// safe against the abandoned store (the documented open/close/
/// delete order is safe at any point — the row pins the
/// teardown-side half).
#[tokio::test(flavor = "multi_thread")]
async fn opens_are_isolated_and_teardown_is_idempotent() {
let factory = SqliteFactory::new("factory-shape");
let a = factory.open().await.unwrap();
let b = factory.open().await.unwrap();
factory.teardown().await.unwrap();
factory.teardown().await.unwrap();
drop(a);
drop(b);
assert!(!factory.dir.exists(), "teardown removed the backing dir");
}
}