Lines
100 %
Functions
Branches
use super::*;
use crate::db::DBError;
use crate::logical::STALE_REVISION;
use crate::telemetry::recorder::build_recorder;
fn refusal(tx_id: Option<Uuid>) -> RunError {
write_failure(BatchError {
tx_id,
error: ServerError::Script(STALE_REVISION.to_string()),
})
}
#[test]
fn a_refused_write_names_the_transaction_and_writes_nothing() {
let tx_id = Uuid::from_u128(7);
assert_eq!(
refusal(Some(tx_id)).to_string(),
format!("{tx_id}: refused: {STALE_REVISION} (nothing was written)")
);
fn a_batch_wide_refusal_names_the_batch() {
let message = refusal(None).to_string();
assert!(message.starts_with("batch: refused: "), "{message}");
fn any_other_write_failure_stays_a_server_error() {
let creation = write_failure(BatchError {
tx_id: Some(Uuid::from_u128(7)),
error: ServerError::Creation,
});
let conflict = write_failure(BatchError {
tx_id: None,
error: ServerError::DB(DBError::WriteConflict),
assert!(matches!(
creation,
RunError::Failed {
source: ServerError::Creation,
..
));
conflict,
source: ServerError::DB(DBError::WriteConflict),
fn a_refused_write_counts_one_refused_item() {
let recorder = build_recorder().expect("recorder");
let _scope = metrics::set_default_local_recorder(&recorder);
let _ = refusal(Some(Uuid::from_u128(7)));
let rendered = recorder.handle().render();
assert!(
rendered.contains(&format!("{SCRIPT_BATCH_ITEMS}{{outcome=\"refused\"}} 1")),
"{rendered}"
assert!(!rendered.contains("outcome=\"failed\""), "{rendered}");
fn a_failed_write_names_the_item_and_writes_nothing() {
let err = write_failure(BatchError {
tx_id: Some(tx_id),
err.to_string(),
format!(
"{tx_id}: failed: {} (nothing was written)",
ServerError::Creation
)
fn a_row_not_found_after_the_lookup_is_not_a_missing_script() {
error: ServerError::DB(DBError::Sqlx(sqlx::Error::RowNotFound)),
assert!(matches!(err, RunError::Failed { .. }), "{err}");