Skip to content

Commit 0bef8a7

Browse files
committed
fix: make no_cache a test-only variable
1 parent d01baf5 commit 0bef8a7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

stackslib/src/net/inv/nakamoto.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub struct InvGenerator {
114114
/// count cache misses for `processed_tenures`
115115
cache_misses: u128,
116116
/// Disable caching (test only)
117+
#[cfg(test)]
117118
no_cache: bool,
118119
}
119120

@@ -124,6 +125,7 @@ impl InvGenerator {
124125
sortitions: HashMap::new(),
125126
tip_ancestor_search_depth: TIP_ANCESTOR_SEARCH_DEPTH,
126127
cache_misses: 0,
128+
#[cfg(test)]
127129
no_cache: false,
128130
}
129131
}
@@ -206,6 +208,17 @@ impl InvGenerator {
206208
Ok(None)
207209
}
208210

211+
#[cfg(not(test))]
212+
fn test_clear_cache(&mut self) {}
213+
214+
/// Clear the cache (test only)
215+
#[cfg(test)]
216+
fn test_clear_cache(&mut self) {
217+
if self.no_cache {
218+
self.processed_tenures.clear();
219+
}
220+
}
221+
209222
/// Get a processed tenure. If it's not cached, then load it from disk.
210223
///
211224
/// Loading it is expensive, so once loaded, store it with the cached processed tenure map
@@ -287,9 +300,7 @@ impl InvGenerator {
287300
self.cache_misses = self.cache_misses.saturating_add(1);
288301
Ok(loaded_info_opt)
289302
};
290-
if self.no_cache {
291-
self.processed_tenures.clear();
292-
}
303+
self.test_clear_cache();
293304
ret
294305
}
295306

0 commit comments

Comments
 (0)