Skip to content

Commit

Permalink
ledger: Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Sep 6, 2024
1 parent 9754d95 commit f426b96
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,38 @@ mod tests {

#[test]
fn concurrent_connections() {
let _ledger = Ledger::new("concurrent_connections");
let ledger = Ledger::new("concurrent_connections");

let _ledger2 = Ledger::new("concurrent_connections");
let ledger2 = Ledger::new("concurrent_connections");

let count = Ledger::get_database_connection_count(&ledger.database.lock().unwrap());
let count2 = Ledger::get_database_connection_count(&ledger2.database.lock().unwrap());

assert_eq!(count, count2);
assert_eq!(count, 2);
}

#[test]
fn concurrent_connection_panics() {
let ledger = Ledger::new("concurrent_connection_panics");

std::panic::set_hook(Box::new(|_info| {
// do nothing
}));

std::thread::spawn(|| {
let _ledger2 = Ledger::new("concurrent_connection_panics");

let _result = std::panic::catch_unwind(|| {
panic!("test panic");
});
})
.join()
.unwrap();

let _ledger3 = Ledger::new("concurrent_connection_panics");

let count = Ledger::get_database_connection_count(&ledger.database.lock().unwrap());
assert_eq!(count, 2);
}
}

0 comments on commit f426b96

Please sign in to comment.