Skip to content

Commit

Permalink
Start fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Shih authored and Brian Shih committed Jan 3, 2024
1 parent d18ec61 commit 3ee0081
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 91 deletions.
9 changes: 6 additions & 3 deletions src/concurrency/concurrency_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ impl ConcurrencyManager {
if let Err(err) = wait_res {
match err {
WaitForGuardError::TxnAborted => return Err(SequenceReqError::TxnAborted),
WaitForGuardError::TxnCommitted => return Err(SequenceReqError::TxnCommitted),
WaitForGuardError::TxnCommitted => {
return Err(SequenceReqError::TxnCommitted)
}
}
};

Expand Down Expand Up @@ -96,10 +98,11 @@ impl ConcurrencyManager {
}
}

#[cfg(test)]
mod test {

use std::time::Duration;


use tokio::{sync::mpsc::channel, time};

#[tokio::test]
async fn test_select() {
Expand Down
67 changes: 39 additions & 28 deletions src/db/db_test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#[cfg(test)]
mod test {

// simple tests that involve writes and reads
#[cfg(test)]
mod single_txn_simple_test {

use std::sync::Arc;


use crate::db::db::{Timestamp, DB};

#[tokio::test]
async fn two_writes_with_different_keys() {
Expand All @@ -29,6 +31,7 @@ mod test {
}
}

#[cfg(test)]
mod transaction_conflicts {
// A read running into an uncommitted intent with a lower timestamp will wait for the
// earlier transaction
Expand All @@ -42,12 +45,9 @@ mod test {
*/
mod write_read {
mod uncommitted_intent_has_lower_timestamp {
use std::sync::Arc;






use crate::db::db::{Timestamp, DB};

#[tokio::test]
async fn read_waits_for_uncommitted_write() {
Expand Down Expand Up @@ -76,9 +76,9 @@ mod test {
// A read running into an uncommitted intent with a higher timestamp ignores the
// intent and does not need to wait.
mod uncommitted_intent_has_higher_timestamp {

use std::sync::Arc;


use crate::db::db::{Timestamp, DB};

#[tokio::test]
async fn ignores_intent_with_higher_timestamp() {
Expand All @@ -98,11 +98,14 @@ mod test {
// A write running into an uncommitted intent with a lower timestamp will wait for the transaction
// to finish.
// A write running into a committed value with a higher tiestamp will bump its timestamp.
#[cfg(test)]
mod write_write {
mod run_into_uncommitted_intent {

use std::sync::Arc;

use crate::db::db::{CommitTxnResult, Timestamp, DB};


use crate::hlc::timestamp::Timestamp as HLCTimestamp;

#[tokio::test]
async fn write_waits_for_uncommitted_write() {
Expand Down Expand Up @@ -145,10 +148,11 @@ mod test {
}
}

#[cfg(test)]
mod run_into_committed_intent {

use std::sync::Arc;


use crate::db::db::{CommitTxnResult, Timestamp, DB};

#[tokio::test]
async fn bump_write_timestamp_before_committing() {
Expand Down Expand Up @@ -196,10 +200,11 @@ mod test {
* If a write detects a read on the same key with a higher timestamp,
* the writeTimestamp is bumped
*/
#[cfg(test)]
mod read_write {

use std::sync::Arc;


use crate::db::db::{CommitTxnResult, Timestamp, DB};

#[tokio::test]
async fn bump_write_timestamp_before_committing() {
Expand Down Expand Up @@ -234,15 +239,13 @@ mod test {
}
}

#[cfg(test)]
mod read_refresh {




#[cfg(test)]
mod read_refresh_success {

use std::sync::Arc;


use crate::db::db::{CommitTxnResult, Timestamp, DB};

#[tokio::test]
async fn read_refresh_from_write_write_conflict() {
Expand Down Expand Up @@ -277,10 +280,12 @@ mod test {

// Advancing a transaction read timestamp from ta to tb is possible
// if we can prove that none of the data

#[cfg(test)]
mod read_refresh_failure {

use std::sync::Arc;


use crate::db::db::{CommitTxnResult, Timestamp, DB};

#[tokio::test]
async fn read_refresh_failure() {
Expand Down Expand Up @@ -321,8 +326,9 @@ mod test {
}
}

#[cfg(test)]
mod abort_txn {

use crate::db::db::{Timestamp, DB};

#[tokio::test]
async fn read_write_after_abort_transaction() {
Expand All @@ -346,10 +352,14 @@ mod test {
}
}

#[cfg(test)]
mod deadlock {

use std::sync::Arc;


use crate::{
db::db::{CommitTxnResult, Timestamp, DB},
storage::str_to_key,
};

#[tokio::test]
async fn conflicting_writes() {
Expand Down Expand Up @@ -454,10 +464,11 @@ mod test {
}
}

#[cfg(test)]
mod run_txn {

use std::sync::Arc;


use crate::db::db::{Timestamp, DB};

#[tokio::test]
async fn reading_its_txn_own_write() {
Expand Down
12 changes: 4 additions & 8 deletions src/interval/interval_tree.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@


use crate::{
llrb::llrb::{NodeKey, NodeValue, RbTree, NIL},
};
use crate::llrb::llrb::{NodeKey, NodeValue, RbTree, NIL};

// TODO: Eviction policy to make sure IntervalTree is bounded
pub struct IntervalTree<K: NodeKey, V: NodeValue> {
Expand Down Expand Up @@ -102,12 +98,12 @@ impl<K: NodeKey, V: NodeValue> IntervalTree<K, V> {
}
}

#[cfg(test)]
mod tests {

#[cfg(test)]
mod get_overlap {



use crate::interval::interval_tree::{IntervalTree, RangeValue};

#[test]
fn test_overlap() {
Expand Down
62 changes: 45 additions & 17 deletions src/latch_manager/latch_interval_btree_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,13 @@ mod Test {
}
}

#[cfg(test)]
mod split {





use crate::latch_manager::latch_interval_btree_test::Test::{
assert_leaf_with_siblings, assert_node, create_test_node, create_test_tree,
find_node_and_parent_with_indices, get_all_leaves, get_start_keys_from_weak_link,
TestInternalNode, TestLeafNode, TestNode,
};

#[test]
fn split_internal() {
Expand Down Expand Up @@ -533,10 +534,11 @@ mod Test {
}
}

#[cfg(test)]
mod insert {

use crate::latch_manager::latch_interval_btree::{BTree, LatchKeyGuard, Range};


use super::{assert_tree, print_tree, TestInternalNode, TestLeafNode, TestNode};

#[test]
fn insert_and_split() {
Expand Down Expand Up @@ -684,10 +686,11 @@ mod Test {
}
}

#[cfg(test)]
mod leaf_underflow {

use std::sync::RwLock;


use crate::latch_manager::latch_interval_btree::{LatchWaiters, LeafNode};

#[test]
fn underflows() {
Expand All @@ -705,9 +708,13 @@ mod Test {
}
}

#[cfg(test)]
mod delete {
#[cfg(test)]
mod core_delete {

use crate::latch_manager::latch_interval_btree_test::Test::{
assert_tree, create_test_tree, print_tree, TestInternalNode, TestLeafNode, TestNode,
};

#[test]
fn internal_node_stealing_from_left_sibling_3_layers() {
Expand Down Expand Up @@ -972,12 +979,16 @@ mod Test {
}

mod leaf_stealing {


mod has_spare_keys {

use std::sync::RwLock;


use crate::latch_manager::{
latch_interval_btree::{LatchWaiters, LeafNode},
latch_interval_btree_test::Test::{
assert_tree, create_test_tree, TestInternalNode, TestLeafNode, TestNode,
},
};

#[test]
fn internal_node() {}
Expand Down Expand Up @@ -1076,7 +1087,10 @@ mod Test {
}

mod stealing_core {

use crate::latch_manager::latch_interval_btree_test::Test::{
assert_tree, create_test_tree, print_tree, TestInternalNode, TestLeafNode,
TestNode,
};

#[test]
fn leaf_steals_left_sibling() {
Expand Down Expand Up @@ -1203,8 +1217,12 @@ mod Test {
}
}

#[cfg(test)]
mod internal_node_stealing {

use crate::latch_manager::latch_interval_btree_test::Test::{
assert_tree, create_test_tree, find_node_and_parent_with_indices, TestInternalNode,
TestLeafNode, TestNode,
};

#[test]
fn simple_steal_from_left_sibling() {
Expand Down Expand Up @@ -1365,9 +1383,15 @@ mod Test {
}
}

#[cfg(test)]
mod merge {

#[cfg(test)]
mod internal_node {

use crate::latch_manager::latch_interval_btree_test::Test::{
assert_tree, create_test_tree, find_node_and_parent_with_indices, TestInternalNode,
TestLeafNode, TestNode,
};

#[test]
fn merge_with_left() {
Expand Down Expand Up @@ -1494,8 +1518,12 @@ mod Test {
}
}

#[cfg(test)]
mod leaf {

use crate::latch_manager::latch_interval_btree_test::Test::{
assert_tree, create_test_tree, find_node_and_parent_with_indices, print_tree,
TestInternalNode, TestLeafNode, TestNode,
};

#[test]
fn merge_with_left_leaf() {
Expand Down
17 changes: 7 additions & 10 deletions src/latch_manager/latch_manager.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@


use rand::Rng;
use tokio::time::{self, Duration};

use crate::execute::request::SpanSet;

use super::{
latch_interval_btree::{BTree, LatchKeyGuard, NodeKey, Range},
};
use super::latch_interval_btree::{BTree, LatchKeyGuard, NodeKey, Range};

pub struct LatchManager<K: NodeKey> {
tree: BTree<K>,
Expand Down Expand Up @@ -86,13 +82,14 @@ impl<K: NodeKey> LatchManager<K> {
}
}

mod Test {
mod Acquire {

mod test {
#[cfg(test)]
mod acquire {
use std::{sync::Arc, time::Duration};


use tokio::time::sleep;


use crate::latch_manager::{latch_interval_btree::Range, latch_manager::LatchManager};

#[tokio::test]
async fn test_select() {
Expand Down
Loading

0 comments on commit 3ee0081

Please sign in to comment.