diff options
Diffstat (limited to 'src/pipeline')
| -rw-r--r-- | src/pipeline/dispatch.rs | 42 | ||||
| -rw-r--r-- | src/pipeline/mod.rs | 14 | ||||
| -rw-r--r-- | src/pipeline/publish.rs | 14 |
3 files changed, 70 insertions, 0 deletions
diff --git a/src/pipeline/dispatch.rs b/src/pipeline/dispatch.rs index 89a8788..aea934e 100644 --- a/src/pipeline/dispatch.rs +++ b/src/pipeline/dispatch.rs @@ -68,7 +68,21 @@ fn dispatcher(cfg: Arc<Config>, db: Db, stop: Arc<AtomicBool>, tx: Sender<String } } +/// The scheduler loop calls it; a test drives single ticks and needs it directly. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> { + dispatch_once_impl(cfg, db, tx) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> { + dispatch_once_impl(cfg, db, tx) +} + +fn dispatch_once_impl(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> { let reaped = builds::reap_expired(db).unwrap_or(0); if reaped > 0 { db::audit_system( @@ -97,7 +111,21 @@ pub fn dispatch_once(cfg: &Config, db: &Db, tx: &Sender<String>) -> Vec<String> ids } +/// Production reaches this through `dispatch_once`, which is the only thing that acts on the answer. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn admissible(cfg: &Config, db: &Db) -> usize { + admissible_impl(cfg, db) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn admissible(cfg: &Config, db: &Db) -> usize { + admissible_impl(cfg, db) +} + +fn admissible_impl(cfg: &Config, db: &Db) -> usize { let in_flight = builds::in_flight(db).unwrap_or(0) as usize; let slots = cfg.max_concurrent_builds.saturating_sub(in_flight); if slots == 0 { @@ -110,7 +138,21 @@ pub fn admissible(cfg: &Config, db: &Db) -> usize { slots } +/// Production reaches this through `admissible`, which is the only thing that acts on the number. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn free_disk_mb(path: &std::path::Path) -> u64 { + free_disk_mb_impl(path) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn free_disk_mb(path: &std::path::Path) -> u64 { + free_disk_mb_impl(path) +} + +fn free_disk_mb_impl(path: &std::path::Path) -> u64 { use std::ffi::CString; let c = match CString::new(path.as_os_str().to_string_lossy().as_bytes()) { Ok(c) => c, diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 42f435f..e14c7a8 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -186,7 +186,21 @@ pub fn run(cfg: &Config, db: &Db, build_id: &str) -> Result<Outcome> { run_with(&ctx) } +/// Production calls `run`, which supplies the real sandbox; a test injects a fake, which is the point of the seam. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn run_with(ctx: &Ctx) -> Result<Outcome> { + run_with_impl(ctx) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn run_with(ctx: &Ctx) -> Result<Outcome> { + run_with_impl(ctx) +} + +fn run_with_impl(ctx: &Ctx) -> Result<Outcome> { std::fs::create_dir_all(&ctx.staging)?; for step in crate::db::model::BUILD_STEPS { if crate::db::builds::cancel_requested(&ctx.db, &ctx.build.id)? { diff --git a/src/pipeline/publish.rs b/src/pipeline/publish.rs index 4e72d35..332e673 100644 --- a/src/pipeline/publish.rs +++ b/src/pipeline/publish.rs @@ -18,7 +18,21 @@ fn lock_repo() -> std::sync::MutexGuard<'static, ()> { } } +/// Publishing calls it; a test checks what landed in the index. +/// +/// Module-internal in a production build, `pub` only under `test-support`: +/// one body behind two visibility declarations, exactly one of which compiles. +#[cfg(feature = "test-support")] pub fn index_world(db: &Db) -> Result<Vec<WorldMember>> { + index_world_impl(db) +} + +#[cfg(not(feature = "test-support"))] +pub(crate) fn index_world(db: &Db) -> Result<Vec<WorldMember>> { + index_world_impl(db) +} + +fn index_world_impl(db: &Db) -> Result<Vec<WorldMember>> { let rels = db::all_published_releases(db)?; let mut out = Vec::new(); for r in rels { |
