Lines
100 %
Functions
Branches
//! Tag setters behind a stalled key holder report the busy condition.
use super::lock_wait::hold_key;
use super::*;
use crate::command::CmdError;
use crate::command::transaction::SetTransactionTag;
use sqlx::Connection;
async fn assert_busy_behind_held_key<T: std::fmt::Debug>(
fx: &Fixture,
write: impl Future<Output = Result<T, CmdError>>,
) -> anyhow::Result<()> {
let mut conn = fx.user.get_connection().await?;
let mut holder = conn.begin().await?;
hold_key(&mut holder, "memo", "m").await?;
let written = write.await;
holder.commit().await?;
let err = written.expect_err("the setter must time out on the held key");
assert!(err.busy().is_some(), "{err:?}");
assert_eq!(fx.tag_rows_with_value("m").await?, 0);
Ok(())
}
#[local_db_sqlx_test]
async fn set_split_tag_behind_a_held_key_is_busy(pool: PgPool) -> anyhow::Result<()> {
let fx = fixture().await?;
let tx_id = fx.create_tx(None).await?;
let split = fx.split_ids(tx_id).await?[0];
let set = SetSplitTag::new()
.user_id(fx.user.id)
.split_id(split)
.tag_name("memo".to_string())
.tag_value("m".to_string())
.run();
assert_busy_behind_held_key(&fx, set).await?;
async fn set_transaction_tag_behind_a_held_key_is_busy(pool: PgPool) -> anyhow::Result<()> {
let set = SetTransactionTag::new()
.transaction_id(tx_id)
async fn set_split_tag(
split: Uuid,
value: &str,
) -> Result<Option<CmdResult>, CmdError> {
SetSplitTag::new()
.tag_value(value.to_string())
.run()
.await
async fn a_blank_split_tag_value_is_an_argument_error(pool: PgPool) -> anyhow::Result<()> {
let err = set_split_tag(&fx, split, " ")
.expect_err("blank value");
assert!(matches!(err, CmdError::Args(_)), "{err:?}");
assert!(err.busy().is_none());
async fn a_missing_split_is_not_found(pool: PgPool) -> anyhow::Result<()> {
let err = set_split_tag(&fx, Uuid::new_v4(), "m")
.expect_err("missing split");
assert!(matches!(err, CmdError::NotFound(_)), "{err:?}");