use super::{AppendReply, AppendTicket};
use crate::store::StoreError;
fn ticket(rx: flume::Receiver<AppendReply>) -> AppendTicket {
#[cfg(feature = "dangerous-test-hooks")]
{
AppendTicket::new(rx, None)
}
#[cfg(not(feature = "dangerous-test-hooks"))]
{
AppendTicket::new(rx)
}
}
#[test]
fn try_check_reports_empty_value_and_disconnect_distinctly() {
let (tx, rx) = flume::bounded::<AppendReply>(1);
let pending = ticket(rx);
assert!(
pending.try_check().is_none(),
"PROPERTY: an empty, still-connected ticket polls to None"
);
tx.send(Err(StoreError::VisibilityFenceActive))
.expect("deliver a reply into the ticket channel");
let delivered = pending
.try_check()
.expect("PROPERTY: a delivered reply must poll to Some");
assert!(
matches!(delivered, Err(StoreError::VisibilityFenceActive)),
"PROPERTY: try_check passes the delivered value through unchanged, got {delivered:?}"
);
let (dead_tx, dead_rx) = flume::bounded::<AppendReply>(1);
drop(dead_tx);
let crashed = ticket(dead_rx);
let outcome = crashed
.try_check()
.expect("PROPERTY: a disconnected ticket must poll to Some");
assert!(
matches!(outcome, Err(StoreError::WriterCrashed)),
"PROPERTY: a disconnected writer must surface WriterCrashed, got {outcome:?}"
);
}