more table store work for password protecting encryption key, also fix unit tests hang in routing table test

This commit is contained in:
John Smith 2023-05-26 20:39:35 +01:00
parent e8392013c3
commit 8001017338
3 changed files with 49 additions and 21 deletions

View File

@ -41,6 +41,9 @@ pub async fn test_routingtable_buckets_round_trip() {
) )
.unwrap(); .unwrap();
// Wrap to close lifetime of 'inner' which is borrowed here so terminate() can succeed
// (it also .write() locks routing table inner)
{
let original_inner = &*original.inner.read(); let original_inner = &*original.inner.read();
let copy_inner = &*copy.inner.read(); let copy_inner = &*copy.inner.read();
@ -69,6 +72,7 @@ pub async fn test_routingtable_buckets_round_trip() {
} }
} }
} }
}
// Even if these are mocks, we should still practice good hygiene. // Even if these are mocks, we should still practice good hygiene.
original.terminate().await; original.terminate().await;

View File

@ -421,6 +421,15 @@ impl TableStore {
/// existing TableDB's column count, the database will be upgraded to add the missing columns /// existing TableDB's column count, the database will be upgraded to add the missing columns
pub async fn open(&self, name: &str, column_count: u32) -> VeilidAPIResult<TableDB> { pub async fn open(&self, name: &str, column_count: u32) -> VeilidAPIResult<TableDB> {
let _async_guard = self.async_lock.lock().await; let _async_guard = self.async_lock.lock().await;
// If we aren't initialized yet, bail
{
let inner = self.inner.lock();
if inner.all_tables_db.is_none() {
apibail_not_initialized!();
}
}
let table_name = self.name_get_or_create(name).await?; let table_name = self.name_get_or_create(name).await?;
// See if this table is already opened // See if this table is already opened
@ -477,6 +486,14 @@ impl TableStore {
/// Delete a TableDB table by name /// Delete a TableDB table by name
pub async fn delete(&self, name: &str) -> VeilidAPIResult<bool> { pub async fn delete(&self, name: &str) -> VeilidAPIResult<bool> {
let _async_guard = self.async_lock.lock().await; let _async_guard = self.async_lock.lock().await;
// If we aren't initialized yet, bail
{
let inner = self.inner.lock();
if inner.all_tables_db.is_none() {
apibail_not_initialized!();
}
}
let Some(table_name) = self.name_get(name).await? else { let Some(table_name) = self.name_get(name).await? else {
// Did not exist in name table // Did not exist in name table
return Ok(false); return Ok(false);
@ -510,6 +527,13 @@ impl TableStore {
/// Rename a TableDB table /// Rename a TableDB table
pub async fn rename(&self, old_name: &str, new_name: &str) -> VeilidAPIResult<()> { pub async fn rename(&self, old_name: &str, new_name: &str) -> VeilidAPIResult<()> {
let _async_guard = self.async_lock.lock().await; let _async_guard = self.async_lock.lock().await;
// If we aren't initialized yet, bail
{
let inner = self.inner.lock();
if inner.all_tables_db.is_none() {
apibail_not_initialized!();
}
}
trace!("TableStore::rename {} -> {}", old_name, new_name); trace!("TableStore::rename {} -> {}", old_name, new_name);
self.name_rename(old_name, new_name).await self.name_rename(old_name, new_name).await
} }

View File

@ -296,7 +296,7 @@ pub async fn test_config() {
} }
let inner = vc.get(); let inner = vc.get();
assert_eq!(inner.program_name, String::from("Veilid")); assert_eq!(inner.program_name, String::from("VeilidCoreTests"));
assert_eq!(inner.namespace, String::from("")); assert_eq!(inner.namespace, String::from(""));
assert_eq!(inner.capabilities.protocol_udp, true); assert_eq!(inner.capabilities.protocol_udp, true);
assert_eq!(inner.capabilities.protocol_connect_tcp, true); assert_eq!(inner.capabilities.protocol_connect_tcp, true);