From 0f93b035f1ff9dce93ac64e33ab6867b5ef9b97e Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Thu, 24 Oct 2024 20:01:57 +0800 Subject: [PATCH] fix unit test failures --- node/sync/src/controllers/serial.rs | 11 ++++------- node/sync/src/lib.rs | 2 ++ node/sync/src/service.rs | 4 +++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/node/sync/src/controllers/serial.rs b/node/sync/src/controllers/serial.rs index 33c61ef..acb5bff 100644 --- a/node/sync/src/controllers/serial.rs +++ b/node/sync/src/controllers/serial.rs @@ -89,9 +89,6 @@ pub struct SerialSyncController { /// Cache for storing and serving gossip messages. file_location_cache: Arc, - - /// 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()); } diff --git a/node/sync/src/lib.rs b/node/sync/src/lib.rs index 3673589..b7067a3 100644 --- a/node/sync/src/lib.rs +++ b/node/sync/src/lib.rs @@ -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, diff --git a/node/sync/src/service.rs b/node/sync/src/service.rs index 22296bb..e119f5e 100644 --- a/node/sync/src/service.rs +++ b/node/sync/src/service.rs @@ -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 {