diff options
Diffstat (limited to 'src/db')
| -rw-r--r-- | src/db/builds/mod.rs | 10 | ||||
| -rw-r--r-- | src/db/builds/steps.rs | 9 | ||||
| -rw-r--r-- | src/db/invariants.rs | 8 | ||||
| -rw-r--r-- | src/db/mod.rs | 28 | ||||
| -rw-r--r-- | src/db/model/mod.rs | 3 | ||||
| -rw-r--r-- | src/db/settings.rs | 6 | ||||
| -rw-r--r-- | src/db/snapshots.rs | 5 | ||||
| -rw-r--r-- | src/db/world.rs | 5 |
8 files changed, 60 insertions, 14 deletions
diff --git a/src/db/builds/mod.rs b/src/db/builds/mod.rs index 2035cfd..fc84335 100644 --- a/src/db/builds/mod.rs +++ b/src/db/builds/mod.rs @@ -127,6 +127,14 @@ pub fn queued(db: &Db, limit: i64) -> Result<Vec<String>> { }) } +/// Lease one named build to a worker. +/// +/// Test-tier only. Production leases a *batch* — `claim_batch` is what the +/// dispatcher runs — and nothing in the crate calls this single-build form. +/// It stays because three test files lease one build at a time on purpose, +/// and a test that wants to reason about one lease should not have to +/// arrange for the batch form to hand back exactly one. +#[cfg(feature = "test-support")] pub fn claim(db: &Db, owner: &str, id: &str, lease_secs: i64) -> Result<bool> { let (owner, id) = (owner.to_string(), id.to_string()); let exp = time::secs_ahead(lease_secs); @@ -291,5 +299,5 @@ pub use steps::{ begin_step, blocked_builds, cancel_superseded, claim_batch, finish_step, in_flight, queue_depth, requeue_transient, retry, set_blocked_on, set_release_in, set_world, - step_status, steps, touch, + step_status, steps, }; diff --git a/src/db/builds/steps.rs b/src/db/builds/steps.rs index 01d7c40..4ffff36 100644 --- a/src/db/builds/steps.rs +++ b/src/db/builds/steps.rs @@ -149,15 +149,6 @@ pub fn blocked_builds(db: &Db) -> Result<Vec<(String, String, Vec<String>)>> { Ok(out) }) } - -pub fn touch(db: &Db, id: &str) -> Result<()> { - let id = id.to_string(); - db.writer.tx(move |tx| { - tx.execute("UPDATE build SET updated_at=?1 WHERE id=?2", params![time::now(), id])?; - Ok(()) - }) -} - pub fn set_release_in(tx: &rusqlite::Transaction<'_>, id: &str, release_id: i64) -> Result<()> { tx.execute("UPDATE build SET release_id=?1 WHERE id=?2", params![release_id, id])?; Ok(()) diff --git a/src/db/invariants.rs b/src/db/invariants.rs index 9853003..e2648fa 100644 --- a/src/db/invariants.rs +++ b/src/db/invariants.rs @@ -4,6 +4,14 @@ use crate::error::Result; // ------------------------------------------------------- invariant helpers -- +/// Repo entries whose candidate was never approved. +/// +/// Test-tier only, and deliberately so: this is an invariant the schema does +/// not enforce and production does not check, so the only thing that keeps it +/// true is that a test asserts it on every run. It is gated rather than moved +/// to `tests/common` because reading it needs this module's private helpers, +/// and widening those to let a test out would be the wrong trade. +#[cfg(feature = "test-support")] pub fn unapproved_index_entries(db: &Db) -> Result<Vec<String>> { db.read(|c| { let mut stmt = c.prepare( diff --git a/src/db/mod.rs b/src/db/mod.rs index 5ac55c9..e42bae4 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -26,6 +26,8 @@ mod world; pub use migrations::MIGRATIONS; pub(crate) use model::StateEnum; +/// Its only caller is the test-tier `world_members`, so it is gated with it. +#[cfg(feature = "test-support")] pub(crate) use model::json_or; pub use model::{ @@ -36,7 +38,9 @@ pub use model::{ notice_kind, }; pub use audit::{AuditEntry, audit, audit_in, audit_system, list_audit}; -pub use invariants::{approved_but_unbuilt, unapproved_index_entries}; +pub use invariants::approved_but_unbuilt; +#[cfg(feature = "test-support")] +pub use invariants::unapproved_index_entries; pub use metrics::{ artifact_bytes_served, build_state_counts, count_index_packages, count_pending_reviews, count_published_releases, count_subscriptions, count_unacknowledged_notices, last_gc_age_secs, @@ -63,8 +67,12 @@ pub use retention::{ mark_release_purged, pkgbase_release_pointers, published_release_ids, record_gc_run, release_artifact_paths, serving_release_ids, }; -pub use settings::{all_settings, set_setting, setting, setting_i64}; -pub use snapshots::{SnapshotRow, put_snapshot, snapshot_by_commit, snapshot_by_id}; +pub use settings::{all_settings, setting, setting_i64}; +#[cfg(feature = "test-support")] +pub use settings::set_setting; +pub use snapshots::{SnapshotRow, put_snapshot, snapshot_by_id}; +#[cfg(feature = "test-support")] +pub use snapshots::snapshot_by_commit; pub use stage_b::{stage_b_cache_get, stage_b_cache_put, stage_b_recent}; pub use staleness::{ NewArtifact, approval_note, candidate_snapshot_id, index_recipes, @@ -75,7 +83,9 @@ pub use subscriptions::{ due_subscriptions, get_subscription, list_subscriptions, note_check, set_subscription_state, subscribe, }; -pub use world::{put_world_snapshot, world_members}; +pub use world::put_world_snapshot; +#[cfg(feature = "test-support")] +pub use world::world_members; pub(crate) fn state_col<T: StateEnum>(col: usize, text: &str) -> rusqlite::Result<T> { T::parse(text).ok_or_else(|| { @@ -160,6 +170,9 @@ type BoxedCall = Box<dyn FnOnce(&mut Connection) + Send>; enum Msg { Call(BoxedCall), + /// Only `Writer::shutdown` constructs this, and only the test tier calls + /// that; the server runs until the process ends. + #[cfg(feature = "test-support")] Shutdown, } @@ -184,6 +197,7 @@ impl Writer { for msg in rx.iter() { match msg { Msg::Call(f) => f(&mut conn), + #[cfg(feature = "test-support")] Msg::Shutdown => break, } } @@ -241,6 +255,12 @@ impl Writer { .map_err(|_| Error::db("writer actor gone")) } + /// Stop the writer actor. + /// + /// Test-tier only: the server runs until the process ends and never + /// quiesces the writer deliberately. Tests use it to prove a worker + /// that dies mid-write leaves the database consistent. +#[cfg(feature = "test-support")] pub fn shutdown(&self) { let _ = self.tx.send(Msg::Shutdown); } diff --git a/src/db/model/mod.rs b/src/db/model/mod.rs index 7c1fbf5..827ce5e 100644 --- a/src/db/model/mod.rs +++ b/src/db/model/mod.rs @@ -193,6 +193,9 @@ impl CandidateRow { } } +/// Test-tier only: the one reader that needed it is `db::world_members`, which +/// is itself gated because nothing in production reads a world snapshot back. +#[cfg(feature = "test-support")] pub(crate) fn json_or<T: serde::de::DeserializeOwned>(s: &str, fallback: T) -> T { serde_json::from_str(s).unwrap_or(fallback) } diff --git a/src/db/settings.rs b/src/db/settings.rs index ebd2c06..d42bb52 100644 --- a/src/db/settings.rs +++ b/src/db/settings.rs @@ -35,6 +35,12 @@ pub fn setting_i64(db: &Db, key: &str, default: i64) -> i64 { } } +/// Write one settings row. +/// +/// Test-tier only: the readers are used in production, the setter is not — +/// settings are written by migration and by the operators' own hands, and no +/// code path in the crate writes one at runtime. +#[cfg(feature = "test-support")] pub fn set_setting(writer: &Writer, key: &str, value: &str) -> Result<()> { let v = value.to_string(); let k = key.to_string(); diff --git a/src/db/snapshots.rs b/src/db/snapshots.rs index 754d7b7..e227eca 100644 --- a/src/db/snapshots.rs +++ b/src/db/snapshots.rs @@ -47,6 +47,11 @@ pub struct SnapshotRow { pub files_json: String, } +/// Find a snapshot by the commit it was taken at. +/// +/// Test-tier only: detection looks snapshots up by id, and nothing in the +/// crate performs a lookup by commit. +#[cfg(feature = "test-support")] pub fn snapshot_by_commit(db: &Db, pkgbase_id: i64, commit: &str) -> Result<Option<SnapshotRow>> { db.read(|c| { c.query_row( diff --git a/src/db/world.rs b/src/db/world.rs index 49779b9..73e327f 100644 --- a/src/db/world.rs +++ b/src/db/world.rs @@ -24,6 +24,11 @@ pub fn put_world_snapshot(writer: &Writer, members: &[WorldMember]) -> Result<i6 }) } +/// Read the members of a world snapshot. +/// +/// Test-tier only: production writes world snapshots and never reads one back +/// member by member; the index is served from the release rows. +#[cfg(feature = "test-support")] pub fn world_members(db: &Db, id: i64) -> Result<Vec<WorldMember>> { db.read(|c| { let s: String = c.query_row( |
