Skip to content

Commit 43e66c3

Browse files
committed
add: cost related tests
1 parent 5357457 commit 43e66c3

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

optd-persistent/init.db

144 KB
Binary file not shown.

optd-persistent/src/cost_model/orm.rs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ mod tests {
688688
async fn test_update_table_stats() {}
689689

690690
#[tokio::test]
691-
#[ignore] // Need to update all tables
692691
async fn test_store_cost() {
693692
const DATABASE_FILE: &str = "test_store_cost.db";
694693
let database_url = copy_init_db(DATABASE_FILE).await;
@@ -712,6 +711,78 @@ mod tests {
712711
assert_eq!(costs[1].epoch_id, epoch_id);
713712
assert_eq!(costs[1].physical_expression_id, physical_expression_id);
714713
assert_eq!(costs[1].cost, cost);
714+
715+
remove_db_file(DATABASE_FILE);
716+
}
717+
718+
#[tokio::test]
719+
async fn test_get_cost() {
720+
const DATABASE_FILE: &str = "test_get_cost.db";
721+
let database_url = copy_init_db(DATABASE_FILE).await;
722+
let mut binding = super::BackendManager::new(Some(&database_url)).await;
723+
let backend_manager = binding.as_mut().unwrap();
724+
let epoch_id = backend_manager
725+
.create_new_epoch("source".to_string(), "data".to_string())
726+
.await
727+
.unwrap();
728+
let physical_expression_id = 1;
729+
let cost = 42;
730+
let _ = backend_manager
731+
.store_cost(physical_expression_id, cost, epoch_id)
732+
.await;
733+
let costs = super::PlanCost::find()
734+
.all(&backend_manager.db)
735+
.await
736+
.unwrap();
737+
assert_eq!(costs.len(), 2); // The first row one is the initialized data
738+
assert_eq!(costs[1].epoch_id, epoch_id);
739+
assert_eq!(costs[1].physical_expression_id, physical_expression_id);
740+
assert_eq!(costs[1].cost, cost);
741+
742+
let res = backend_manager
743+
.get_cost(physical_expression_id)
744+
.await
745+
.unwrap();
746+
assert_eq!(res.unwrap(), cost);
747+
748+
remove_db_file(DATABASE_FILE);
749+
}
750+
751+
#[tokio::test]
752+
async fn test_get_cost_analysis() {
753+
const DATABASE_FILE: &str = "test_get_cost_analysis.db";
754+
let database_url = copy_init_db(DATABASE_FILE).await;
755+
let mut binding = super::BackendManager::new(Some(&database_url)).await;
756+
let backend_manager = binding.as_mut().unwrap();
757+
let epoch_id = backend_manager
758+
.create_new_epoch("source".to_string(), "data".to_string())
759+
.await
760+
.unwrap();
761+
let physical_expression_id = 1;
762+
let cost = 42;
763+
let _ = backend_manager
764+
.store_cost(physical_expression_id, cost, epoch_id)
765+
.await;
766+
let costs = super::PlanCost::find()
767+
.all(&backend_manager.db)
768+
.await
769+
.unwrap();
770+
assert_eq!(costs.len(), 2); // The first row one is the initialized data
771+
assert_eq!(costs[1].epoch_id, epoch_id);
772+
assert_eq!(costs[1].physical_expression_id, physical_expression_id);
773+
assert_eq!(costs[1].cost, cost);
774+
println!("{:?}", costs);
775+
776+
// Retrieve physical_expression_id 1 and epoch_id 1
777+
let res = backend_manager
778+
.get_cost_analysis(physical_expression_id, 1)
779+
.await
780+
.unwrap();
781+
782+
// The cost in the dummy data is 10
783+
assert_eq!(res.unwrap(), 10);
784+
785+
remove_db_file(DATABASE_FILE);
715786
}
716787

717788
#[tokio::test]

0 commit comments

Comments
 (0)