zebra_chain/chain_sync_status/mock.rs
1//! Test-only mocks for [`ChainSyncStatus`].
2
3use std::sync::{
4 atomic::{AtomicBool, Ordering},
5 Arc,
6};
7
8use super::ChainSyncStatus;
9
10/// A mock [`ChainSyncStatus`] implementation that allows setting the status externally.
11#[derive(Clone, Default)]
12pub struct MockSyncStatus {
13 is_close_to_tip: Arc<AtomicBool>,
14}
15
16impl MockSyncStatus {
17 /// Sets mock sync status determining the return value of `is_close_to_tip()`
18 pub fn set_is_close_to_tip(&mut self, is_close_to_tip: bool) {
19 self.is_close_to_tip
20 .store(is_close_to_tip, Ordering::SeqCst);
21 }
22}
23
24impl ChainSyncStatus for MockSyncStatus {
25 fn is_close_to_tip(&self) -> bool {
26 self.is_close_to_tip.load(Ordering::SeqCst)
27 }
28}