Skip to content

Commit

Permalink
datastore: add test test_update_no_such_index
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Jan 20, 2025
1 parent 20b7bb8 commit 9e692b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
35 changes: 31 additions & 4 deletions crates/core/src/db/datastore/locking_tx_datastore/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,10 +1261,7 @@ mod tests {
}

fn basic_table_schema() -> TableSchema {
TableSchema::new(
TableId::SENTINEL,
"Foo".into(),
map_array(basic_table_schema_cols()),
basic_table_schema_with_indices(
vec![
IndexSchema {
index_id: IndexId::SENTINEL,
Expand Down Expand Up @@ -1297,6 +1294,16 @@ mod tests {
}),
},
],
)
}

fn basic_table_schema_with_indices(indices: Vec<IndexSchema>, constraints: Vec<ConstraintSchema>) -> TableSchema {
TableSchema::new(
TableId::SENTINEL,
"Foo".into(),
map_array(basic_table_schema_cols()),
indices,
constraints,
vec![SequenceSchema {
sequence_id: SequenceId::SENTINEL,
table_id: TableId::SENTINEL,
Expand Down Expand Up @@ -2068,6 +2075,26 @@ mod tests {
Ok(())
}

#[test]
fn test_update_no_such_index() -> ResultTest<()> {
let datastore = get_datastore()?;
let mut tx = datastore.begin_mut_tx(IsolationLevel::Serializable, Workload::ForTests);
let schema = basic_table_schema_with_indices([].into(), [].into());
let table_id = datastore.create_table_mut_tx(&mut tx, schema)?;

// There are no indices attached to `table_id`.
let index_id = 0.into();
let row = to_vec(&u32_str_u32(42, "foo", 24)).unwrap();
let err = datastore
.update_mut_tx(&mut tx, table_id, index_id, &row)
.expect_err("update using a non-existent index should error")
.into_index()
.expect("the error should be an index error");
assert_eq!(err, IndexError::NotFound(index_id));

Ok(())
}

#[test]
/// Test that two read-only TXes can operate concurrently without deadlock or blocking,
/// and that both observe correct results for a simple table scan.
Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::num::ParseIntError;
use std::path::PathBuf;
use std::sync::{MutexGuard, PoisonError};

use enum_as_inner::EnumAsInner;
use hex::FromHexError;
use spacetimedb_expr::errors::TypingError;
use spacetimedb_sats::AlgebraicType;
Expand Down Expand Up @@ -171,7 +172,7 @@ pub enum SequenceError {
MultiColumnAutoInc(TableId, ColList),
}

#[derive(Error, Debug)]
#[derive(Error, Debug, EnumAsInner)]
pub enum DBError {
#[error("LibError: {0}")]
Lib(#[from] LibError),
Expand Down

0 comments on commit 9e692b8

Please sign in to comment.