mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-04-04 15:35:18 +00:00
fix unit test failures
This commit is contained in:
parent
cebc3c8247
commit
0f93b035f1
@ -89,9 +89,6 @@ pub struct SerialSyncController {
|
|||||||
|
|
||||||
/// Cache for storing and serving gossip messages.
|
/// Cache for storing and serving gossip messages.
|
||||||
file_location_cache: Arc<FileLocationCache>,
|
file_location_cache: Arc<FileLocationCache>,
|
||||||
|
|
||||||
/// Whether to find files from neighbors only.
|
|
||||||
neighbors_only: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SerialSyncController {
|
impl SerialSyncController {
|
||||||
@ -118,7 +115,6 @@ impl SerialSyncController {
|
|||||||
ctx,
|
ctx,
|
||||||
store,
|
store,
|
||||||
file_location_cache,
|
file_location_cache,
|
||||||
neighbors_only: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +163,7 @@ impl SerialSyncController {
|
|||||||
let (published, num_new_peers) = if !self.goal.is_all_chunks() {
|
let (published, num_new_peers) = if !self.goal.is_all_chunks() {
|
||||||
self.publish_find_chunks();
|
self.publish_find_chunks();
|
||||||
(true, 0)
|
(true, 0)
|
||||||
} else if self.neighbors_only {
|
} else if self.config.neighbors_only {
|
||||||
self.do_publish_find_file();
|
self.do_publish_find_file();
|
||||||
(true, 0)
|
(true, 0)
|
||||||
} else {
|
} else {
|
||||||
@ -219,7 +215,7 @@ impl SerialSyncController {
|
|||||||
tx_id: self.tx_id,
|
tx_id: self.tx_id,
|
||||||
num_shard: shard_config.num_shard,
|
num_shard: shard_config.num_shard,
|
||||||
shard_id: shard_config.shard_id,
|
shard_id: shard_config.shard_id,
|
||||||
neighbors_only: self.neighbors_only,
|
neighbors_only: self.config.neighbors_only,
|
||||||
timestamp: timestamp_now(),
|
timestamp: timestamp_now(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -666,7 +662,7 @@ impl SerialSyncController {
|
|||||||
} else {
|
} else {
|
||||||
// FindFile timeout
|
// FindFile timeout
|
||||||
if since.elapsed() >= self.config.peer_find_timeout {
|
if since.elapsed() >= self.config.peer_find_timeout {
|
||||||
if self.neighbors_only {
|
if self.config.neighbors_only {
|
||||||
self.state = SyncState::Failed {
|
self.state = SyncState::Failed {
|
||||||
reason: FailureReason::TimeoutFindFile,
|
reason: FailureReason::TimeoutFindFile,
|
||||||
};
|
};
|
||||||
@ -1547,6 +1543,7 @@ mod tests {
|
|||||||
|
|
||||||
controller.on_response(peer_id, chunks).await;
|
controller.on_response(peer_id, chunks).await;
|
||||||
assert_eq!(*controller.get_status(), SyncState::Completed);
|
assert_eq!(*controller.get_status(), SyncState::Completed);
|
||||||
|
assert!(matches!(network_recv.try_recv().unwrap(), NetworkMessage::AnnounceLocalFile { .. }));
|
||||||
assert!(network_recv.try_recv().is_err());
|
assert!(network_recv.try_recv().is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ use std::{
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
// sync service config
|
// sync service config
|
||||||
|
pub neighbors_only: bool,
|
||||||
#[serde(deserialize_with = "deserialize_duration")]
|
#[serde(deserialize_with = "deserialize_duration")]
|
||||||
pub heartbeat_interval: Duration,
|
pub heartbeat_interval: Duration,
|
||||||
pub auto_sync_enabled: bool,
|
pub auto_sync_enabled: bool,
|
||||||
@ -64,6 +65,7 @@ impl Default for Config {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
// sync service config
|
// sync service config
|
||||||
|
neighbors_only: false,
|
||||||
heartbeat_interval: Duration::from_secs(5),
|
heartbeat_interval: Duration::from_secs(5),
|
||||||
auto_sync_enabled: false,
|
auto_sync_enabled: false,
|
||||||
max_sync_files: 8,
|
max_sync_files: 8,
|
||||||
|
@ -1558,6 +1558,7 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
wait_for_tx_finalized(runtime.store.clone(), tx_seq).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());
|
assert!(!runtime.store.check_tx_completed(0).unwrap());
|
||||||
|
|
||||||
@ -1582,6 +1583,7 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
wait_for_tx_finalized(runtime.store, tx_seq).await;
|
wait_for_tx_finalized(runtime.store, tx_seq).await;
|
||||||
|
assert!(matches!(runtime.network_recv.try_recv().unwrap(), NetworkMessage::AnnounceLocalFile { .. }));
|
||||||
|
|
||||||
sync_send
|
sync_send
|
||||||
.notify(SyncMessage::PeerDisconnected {
|
.notify(SyncMessage::PeerDisconnected {
|
||||||
|
Loading…
Reference in New Issue
Block a user