liminal-server 0.25.4

Standalone server for the liminal messaging bus
Documentation
//! Self-stream pruning under the full-service storage contract.

use super::*;

/// R3b F4: a prune the drainer makes to keep a stream in its bound is self
/// work and wakes no tick; an external read after it (the control) does.
/// Full services validate an existing persistent home before opening a store.
#[test]
fn a_self_prune_wakes_no_cost_tick() -> Result<(), Box<dyn Error>> {
    use liminal::durability::bridge::block_on;
    let persistence_directory = tempfile::tempdir()?;
    let (services, supervisor, sink) =
        bounded_self_streams(64, 1, Some(persistence_directory.path()))?;
    let wake = services.signals().wake();
    let row = || {
        CostWindow::new(StoreCounts::default(), SelfWork::default())
            .prepare(services.store_counts().snapshot(), SelfWork::default())
            .ok_or("fixture has no counted startup work")
    };
    let mut publisher = Arc::clone(&sink);
    CostSink::publish(&mut publisher, &row()?)?;
    let mut tick = idle_tick(&wake, &sink)?;
    let before = services.store_counts().snapshot();
    CostSink::publish(&mut publisher, &row()?)?;
    let pruned = services.store_counts().snapshot().since(&before);
    let (_, own) = CostSink::snapshot(&sink)?;
    let after_prune = tick_now(&mut tick);
    let read = block_on(services.durable_store().read_at("external-missing:0", 91));
    let after_external = tick_now(&mut tick);
    drop(tick);
    supervisor.shutdown();
    assert_eq!((pruned.truncate_calls, pruned.truncate_rows), (1, 1));
    assert_eq!((own.prunes, own.rows_pruned), (1, 1));
    assert!(read??.is_none());
    assert!(
        after_prune.is_pending(),
        "a self prune woke the cost tick: {after_prune:?}"
    );
    assert!(
        matches!(after_external, std::task::Poll::Ready(Ok(()))),
        "an external read after the prune did not wake the cost tick: {after_external:?}"
    );
    Ok(())
}