fix unit test failures

This commit is contained in:
boqiu 2024-10-24 20:01:57 +08:00
parent cebc3c8247
commit 0f93b035f1
3 changed files with 9 additions and 8 deletions

View File

@ -89,9 +89,6 @@ pub struct SerialSyncController {
/// Cache for storing and serving gossip messages.
file_location_cache: Arc<FileLocationCache>,
/// Whether to find files from neighbors only.
neighbors_only: bool,
}
impl SerialSyncController {
@ -118,7 +115,6 @@ impl SerialSyncController {
ctx,
store,
file_location_cache,
neighbors_only: true,
}
}
@ -167,7 +163,7 @@ impl SerialSyncController {
let (published, num_new_peers) = if !self.goal.is_all_chunks() {
self.publish_find_chunks();
(true, 0)
} else if self.neighbors_only {
} else if self.config.neighbors_only {
self.do_publish_find_file();
(true, 0)
} else {
@ -219,7 +215,7 @@ impl SerialSyncController {
tx_id: self.tx_id,
num_shard: shard_config.num_shard,
shard_id: shard_config.shard_id,
neighbors_only: self.neighbors_only,
neighbors_only: self.config.neighbors_only,
timestamp: timestamp_now(),
}));
}
@ -666,7 +662,7 @@ impl SerialSyncController {
} else {
// FindFile timeout
if since.elapsed() >= self.config.peer_find_timeout {
if self.neighbors_only {
if self.config.neighbors_only {
self.state = SyncState::Failed {
reason: FailureReason::TimeoutFindFile,
};
@ -1547,6 +1543,7 @@ mod tests {
controller.on_response(peer_id, chunks).await;
assert_eq!(*controller.get_status(), SyncState::Completed);
assert!(matches!(network_recv.try_recv().unwrap(), NetworkMessage::AnnounceLocalFile { .. }));
assert!(network_recv.try_recv().is_err());
}

View File

@ -21,6 +21,7 @@ use std::{
#[serde(default)]
pub struct Config {
// sync service config
pub neighbors_only: bool,
#[serde(deserialize_with = "deserialize_duration")]
pub heartbeat_interval: Duration,
pub auto_sync_enabled: bool,
@ -64,6 +65,7 @@ impl Default for Config {
fn default() -> Self {
Self {
// sync service config
neighbors_only: false,
heartbeat_interval: Duration::from_secs(5),
auto_sync_enabled: false,
max_sync_files: 8,

View File

@ -1558,6 +1558,7 @@ mod tests {
.await;
wait_for_tx_finalized(runtime.store.clone(), tx_seq).await;
assert!(matches!(runtime.network_recv.try_recv().unwrap(), NetworkMessage::AnnounceLocalFile { .. }));
assert!(!runtime.store.check_tx_completed(0).unwrap());
@ -1567,7 +1568,7 @@ mod tests {
.request(SyncRequest::SyncFile { tx_seq })
.await
.unwrap();
receive_dial(&mut runtime, &sync_send).await;
receive_chunk_request(
@ -1582,6 +1583,7 @@ mod tests {
.await;
wait_for_tx_finalized(runtime.store, tx_seq).await;
assert!(matches!(runtime.network_recv.try_recv().unwrap(), NetworkMessage::AnnounceLocalFile { .. }));
sync_send
.notify(SyncMessage::PeerDisconnected {