Skip to content

Commit

Permalink
DbFixturesWithModel always include VirtualSystemMapping (#28140)
Browse files Browse the repository at this point in the history
when we create db fixtures for tests that include application tables, we should always include the VirtualSystemMapping which is also part of the model.

`DbFixtures::new_with_model` includes this, but `DbFixtures::new().with_model()` does not. change everything to use `DbFixtures::new_with_model`

GitOrigin-RevId: 5005e4ce6f8f50999d406af731acf7c07e53e058
  • Loading branch information
ldanilek authored and Convex, Inc. committed Jul 19, 2024
1 parent abc47b8 commit 2294b14
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 61 deletions.
2 changes: 1 addition & 1 deletion crates/database/src/bootstrap_model/system_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a, RT: Runtime> SystemMetadataModel<'a, RT> {
if cfg!(any(test, feature = "testing")) {
format!(
"Failed to find system table {table} in a test. Try initializing system \
tables with:\nDbFixtures::new(&rt).await?.with_model().await?"
tables with:\nDbFixtures::new_with_model(&rt).await?"
)
} else {
format!("Failed to find system table {table}")
Expand Down
2 changes: 1 addition & 1 deletion crates/file_storage/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn setup_file_storage(

#[convex_macro::test_runtime]
async fn test_get_file_404(rt: TestRuntime) -> anyhow::Result<()> {
let database = DbFixtures::new(&rt).await?.with_model().await?.db;
let database = DbFixtures::new_with_model(&rt).await?.db;
let file_storage = setup_file_storage(rt.clone(), &database)?;

let bogus_storage_id = FileStorageId::LegacyStorageId(rt.new_uuid_v4().into());
Expand Down
8 changes: 3 additions & 5 deletions crates/function_runner/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ mod tests {
},
test_helpers::bogus_udf_request,
};
use model::initialize_application_system_tables;
use model::test_helpers::DbFixturesWithModel;
use runtime::testing::TestRuntime;
use storage::LocalDirStorage;

Expand Down Expand Up @@ -687,8 +687,7 @@ mod tests {
};
let function_runner_core = FunctionRunnerCore::_new(rt.clone(), storage, 50, 2).await?;
let (mut pause1, pause_client1) = PauseController::new([PAUSE_REQUEST]);
let DbFixtures { db, .. } = DbFixtures::new(&rt).await?;
initialize_application_system_tables(&db).await?;
let DbFixtures { db, .. } = DbFixtures::new_with_model(&rt).await?;
let client1 = "client1";
let (sender, _rx1) = oneshot::channel();
let request = bogus_udf_request(&db, client1, Some(pause_client1), sender).await?;
Expand All @@ -713,8 +712,7 @@ mod tests {
};
let function_runner_core = FunctionRunnerCore::_new(rt.clone(), storage, 50, 2).await?;
let (mut pause1, pause_client1) = PauseController::new([PAUSE_REQUEST]);
let DbFixtures { db, .. } = DbFixtures::new(&rt).await?;
initialize_application_system_tables(&db).await?;
let DbFixtures { db, .. } = DbFixtures::new_with_model(&rt).await?;
let client = "client";
let (sender, _rx1) = oneshot::channel();
let request = bogus_udf_request(&db, client, Some(pause_client1), sender).await?;
Expand Down
4 changes: 1 addition & 3 deletions crates/isolate/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<RT: Runtime, P: Persistence + Clone> UdfTest<RT, P> {
db: database,
search_storage,
..
} = DbFixtures::new_with_args(
} = DbFixtures::new_with_model_and_args(
&rt,
DbFixturesArgs {
tp: Some(persistence.clone()),
Expand All @@ -278,8 +278,6 @@ impl<RT: Runtime, P: Persistence + Clone> UdfTest<RT, P> {
..Default::default()
},
)
.await?
.with_model()
.await?;
database
.start_search_and_vector_bootstrap(PauseClient::new())
Expand Down
2 changes: 1 addition & 1 deletion crates/model/src/backend_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ mod tests {

#[convex_macro::test_runtime]
async fn test_toggle_backend_state(rt: TestRuntime) -> anyhow::Result<()> {
let db = DbFixtures::new(&rt).await?.with_model().await?.db;
let db = DbFixtures::new_with_model(&rt).await?.db;
let mut tx = db.begin_system().await?;
let mut model = BackendStateModel::new(&mut tx);
let starting_state = model.get_backend_state().await?;
Expand Down
6 changes: 3 additions & 3 deletions crates/model/src/config/index_diff_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async fn get_index_diff_with_new_indexes_from_two_tables_returns_added_indexes_f
async fn get_index_diff_with_existing_unmodified_enabled_indexes_ignores_them(
rt: TestRuntime,
) -> anyhow::Result<()> {
let DbFixtures { tp, db, .. } = DbFixtures::new(&rt).await?.with_model().await?;
let DbFixtures { tp, db, .. } = DbFixtures::new_with_model(&rt).await?;

let table_name1 = "table1";
let index_name1 = "index1";
Expand All @@ -217,7 +217,7 @@ async fn get_index_diff_with_existing_unmodified_enabled_indexes_ignores_them(
// backfilled index as identical.
#[convex_macro::test_runtime]
async fn test_clean_index_diff_after_backfill(rt: TestRuntime) -> anyhow::Result<()> {
let DbFixtures { tp, db, .. } = DbFixtures::new(&rt).await?.with_model().await?;
let DbFixtures { tp, db, .. } = DbFixtures::new_with_model(&rt).await?;

let table_name = "table1";
let index_name = "index1";
Expand All @@ -243,7 +243,7 @@ async fn test_clean_index_diff_after_backfill(rt: TestRuntime) -> anyhow::Result
async fn get_index_diff_with_existing_unmodified_backfilled_indexes_prepare_behavior_ignores_it(
rt: TestRuntime,
) -> anyhow::Result<()> {
let DbFixtures { tp, db, .. } = DbFixtures::new(&rt).await?.with_model().await?;
let DbFixtures { tp, db, .. } = DbFixtures::new_with_model(&rt).await?;

let table_name = "table1";
let index_name = "index1";
Expand Down
10 changes: 5 additions & 5 deletions crates/model/src/config/index_limits_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async fn commit_schema(

#[convex_macro::test_runtime]
async fn insert_vector_doc_under_vector_limit_succeeds(rt: TestRuntime) -> anyhow::Result<()> {
let DbFixtures { db, tp, .. } = DbFixtures::new(&rt).await?.with_model().await?;
let DbFixtures { db, tp, .. } = DbFixtures::new_with_model(&rt).await?;
commit_schema(&rt, tp, &db).await?;

let vector = rt.with_rng(random_vector_value);
Expand All @@ -77,7 +77,7 @@ async fn insert_vector_doc_under_vector_limit_succeeds(rt: TestRuntime) -> anyho

#[convex_macro::test_runtime]
async fn insert_vector_doc_over_vector_limit_fails(rt: TestRuntime) -> anyhow::Result<()> {
let DbFixtures { db, tp, .. } = DbFixtures::new(&rt).await?.with_model().await?;
let DbFixtures { db, tp, .. } = DbFixtures::new_with_model(&rt).await?;
commit_schema(&rt, tp, &db).await?;

let vector = rt.with_rng(random_vector_value);
Expand Down Expand Up @@ -106,7 +106,7 @@ fn assert_vector_index_too_large_error(result: anyhow::Result<Timestamp>) -> any
async fn insert_doc_in_other_table_over_vector_limit_succeeds(
rt: TestRuntime,
) -> anyhow::Result<()> {
let DbFixtures { db, tp, .. } = DbFixtures::new(&rt).await?.with_model().await?;
let DbFixtures { db, tp, .. } = DbFixtures::new_with_model(&rt).await?;
commit_schema(&rt, tp, &db).await?;

let vector = random_1536_vector_value(&rt);
Expand All @@ -121,7 +121,7 @@ async fn insert_doc_in_other_table_over_vector_limit_succeeds(

#[convex_macro::test_runtime]
async fn insert_doc_in_same_table_without_vector_succeeds(rt: TestRuntime) -> anyhow::Result<()> {
let DbFixtures { db, tp, .. } = DbFixtures::new(&rt).await?.with_model().await?;
let DbFixtures { db, tp, .. } = DbFixtures::new_with_model(&rt).await?;
commit_schema(&rt, tp, &db).await?;

let mut tx = db.begin(Identity::system()).await?;
Expand Down Expand Up @@ -149,7 +149,7 @@ fn random_1536_vector_value(rt: &TestRuntime) -> ConvexValue {
// for a tombstone, which decreases the total size.
#[convex_macro::test_runtime]
async fn insert_and_delete_vector_doc_over_hard_limit_fails(rt: TestRuntime) -> anyhow::Result<()> {
let DbFixtures { db, tp, .. } = DbFixtures::new(&rt).await?.with_model().await?;
let DbFixtures { db, tp, .. } = DbFixtures::new_with_model(&rt).await?;

commit_schema(&rt, tp, &db).await?;

Expand Down
Loading

0 comments on commit 2294b14

Please sign in to comment.