fix tests

This commit is contained in:
Christien Rioux 2023-12-05 21:07:42 -05:00
parent b46fd7690f
commit 05f89e070c
4 changed files with 45 additions and 33 deletions

View File

@ -291,40 +291,42 @@ impl StorageManager {
/// Close an opened local record /// Close an opened local record
pub async fn close_record(&self, key: TypedKey) -> VeilidAPIResult<()> { pub async fn close_record(&self, key: TypedKey) -> VeilidAPIResult<()> {
let (opened_record, opt_rpc_processor) = { let (opt_opened_record, opt_rpc_processor) = {
let mut inner = self.lock().await?; let mut inner = self.lock().await?;
(inner.close_record(key)?, inner.opt_rpc_processor.clone()) (inner.close_record(key)?, inner.opt_rpc_processor.clone())
}; };
// Send a one-time cancel request for the watch if we have one and we're online // Send a one-time cancel request for the watch if we have one and we're online
if let Some(active_watch) = opened_record.active_watch() { if let Some(opened_record) = opt_opened_record {
if let Some(rpc_processor) = opt_rpc_processor { if let Some(active_watch) = opened_record.active_watch() {
// Use the safety selection we opened the record with if let Some(rpc_processor) = opt_rpc_processor {
// Use the writer we opened with as the 'watcher' as well // Use the safety selection we opened the record with
let opt_owvresult = self // Use the writer we opened with as the 'watcher' as well
.outbound_watch_value( let opt_owvresult = self
rpc_processor, .outbound_watch_value(
key, rpc_processor,
ValueSubkeyRangeSet::full(), key,
Timestamp::new(0), ValueSubkeyRangeSet::full(),
0, Timestamp::new(0),
opened_record.safety_selection(), 0,
opened_record.writer().cloned(), opened_record.safety_selection(),
Some(active_watch.watch_node), opened_record.writer().cloned(),
) Some(active_watch.watch_node),
.await?; )
if let Some(owvresult) = opt_owvresult { .await?;
if owvresult.expiration_ts.as_u64() != 0 { if let Some(owvresult) = opt_owvresult {
log_stor!(debug if owvresult.expiration_ts.as_u64() != 0 {
"close record watch cancel got unexpected expiration: {}", log_stor!(debug
owvresult.expiration_ts "close record watch cancel got unexpected expiration: {}",
); owvresult.expiration_ts
);
}
} else {
log_stor!(debug "close record watch cancel unsuccessful");
} }
} else { } else {
log_stor!(debug "close record watch cancel unsuccessful"); log_stor!(debug "skipping last-ditch watch cancel because we are offline");
} }
} else {
log_stor!(debug "skipping last-ditch watch cancel because we are offline");
} }
} }
@ -336,6 +338,7 @@ impl StorageManager {
// Ensure the record is closed // Ensure the record is closed
self.close_record(key).await?; self.close_record(key).await?;
// Get record from the local store
let mut inner = self.lock().await?; let mut inner = self.lock().await?;
let Some(local_record_store) = inner.local_record_store.as_mut() else { let Some(local_record_store) = inner.local_record_store.as_mut() else {
apibail_not_initialized!(); apibail_not_initialized!();
@ -526,8 +529,11 @@ impl StorageManager {
) )
.await?; .await?;
// Whatever record we got back, store it locally, might be newer than the one we asked to save // Keep the list of nodes that returned a value for later reference
let mut inner = self.lock().await?; let mut inner = self.lock().await?;
inner.set_value_nodes(key, result.value_nodes)?;
// Whatever record we got back, store it locally, might be newer than the one we asked to save
inner inner
.handle_set_local_value(key, subkey, result.signed_value_data.clone()) .handle_set_local_value(key, subkey, result.signed_value_data.clone())
.await?; .await?;

View File

@ -480,11 +480,15 @@ impl StorageManagerInner {
Ok(()) Ok(())
} }
pub fn close_record(&mut self, key: TypedKey) -> VeilidAPIResult<OpenedRecord> { pub fn close_record(&mut self, key: TypedKey) -> VeilidAPIResult<Option<OpenedRecord>> {
let Some(opened_record) = self.opened_records.remove(&key) else { let Some(local_record_store) = self.local_record_store.as_mut() else {
apibail_generic!("record not open"); apibail_not_initialized!();
}; };
Ok(opened_record) if local_record_store.peek_record(key, |_| {}).is_none() {
return Err(VeilidAPIError::key_not_found(key));
}
Ok(self.opened_records.remove(&key))
} }
pub(super) async fn handle_get_local_value( pub(super) async fn handle_get_local_value(

View File

@ -16,7 +16,6 @@ impl RecordData {
self.signed_value_data.data_size() self.signed_value_data.data_size()
} }
pub fn total_size(&self) -> usize { pub fn total_size(&self) -> usize {
(mem::size_of::<Self>() - mem::size_of::<SignedValueData>()) mem::size_of::<Self>() + self.signed_value_data.total_size()
+ self.signed_value_data.total_size()
} }
} }

View File

@ -229,6 +229,9 @@ pub fn config_callback(key: String) -> ConfigCallbackReturn {
"network.dht.remote_max_records" => Ok(Box::new(4096u32)), "network.dht.remote_max_records" => Ok(Box::new(4096u32)),
"network.dht.remote_max_subkey_cache_memory_mb" => Ok(Box::new(64u32)), "network.dht.remote_max_subkey_cache_memory_mb" => Ok(Box::new(64u32)),
"network.dht.remote_max_storage_space_mb" => Ok(Box::new(64u32)), "network.dht.remote_max_storage_space_mb" => Ok(Box::new(64u32)),
"network.dht.public_watch_limit" => Ok(Box::new(32u32)),
"network.dht.member_watch_limit" => Ok(Box::new(8u32)),
"network.dht.max_watch_expiration_ms" => Ok(Box::new(600_000u32)),
"network.upnp" => Ok(Box::new(false)), "network.upnp" => Ok(Box::new(false)),
"network.detect_address_changes" => Ok(Box::new(true)), "network.detect_address_changes" => Ok(Box::new(true)),
"network.restricted_nat_retries" => Ok(Box::new(0u32)), "network.restricted_nat_retries" => Ok(Box::new(0u32)),