Skip to content

Commit 4fb2c61

Browse files
committed
Make sure state starts at close to now tick
This commit ensures that at startup the state does not start at an arbitrary tick but at one synchronized with the logrotate_fs. In practice this comes to the same thing -- today -- but it's an easy bug to trip on in the future. Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent 89b7f7a commit 4fb2c61

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lading/src/generator/file_gen/logrotate_fs.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ impl Server {
113113
&config.variant,
114114
)?;
115115

116+
let start_time = std::time::Instant::now();
117+
let start_time_system = std::time::SystemTime::now();
116118
let state = model::State::new(
117119
&mut rng,
120+
start_time.elapsed().as_secs(),
118121
config.bytes_per_second.get_bytes() as u64,
119122
config.total_rotations,
120123
config.maximum_bytes_per_log.get_bytes() as u64,
@@ -131,8 +134,8 @@ impl Server {
131134
let fs = LogrotateFS {
132135
state: Arc::new(Mutex::new(state)),
133136
open_files: Arc::new(Mutex::new(HashMap::new())),
134-
start_time: std::time::Instant::now(),
135-
start_time_system: std::time::SystemTime::now(),
137+
start_time,
138+
start_time_system,
136139
};
137140

138141
let options = vec![

lading/src/generator/file_gen/logrotate_fs/model.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,10 @@ pub(crate) enum NodeType {
347347
impl State {
348348
/// Create a new instance of `State`.
349349
#[tracing::instrument(skip(rng, block_cache))]
350+
#[allow(clippy::too_many_arguments)]
350351
pub(crate) fn new<R>(
351352
rng: &mut R,
353+
initial_tick: Tick,
352354
bytes_per_tick: u64,
353355
max_rotations: u8,
354356
max_bytes_per_file: u64,
@@ -374,7 +376,7 @@ impl State {
374376
let mut state = State {
375377
nodes,
376378
root_inode,
377-
now: 0,
379+
now: initial_tick,
378380
block_cache,
379381
max_bytes_per_file,
380382
max_rotations,
@@ -955,6 +957,7 @@ mod test {
955957
1024u64..=500_000u64, // max_bytes_per_file
956958
1u8..=4u8, // max_depth
957959
1u16..=16u16, // concurrent_logs
960+
1u64..=1000u64, // initial_tick
958961
)
959962
.prop_map(
960963
|(
@@ -964,6 +967,7 @@ mod test {
964967
max_bytes_per_file,
965968
max_depth,
966969
concurrent_logs,
970+
initial_tick,
967971
)| {
968972
let mut rng = StdRng::seed_from_u64(seed);
969973
let block_cache = block::Cache::fixed(
@@ -976,6 +980,7 @@ mod test {
976980

977981
State::new(
978982
&mut rng,
983+
initial_tick,
979984
bytes_per_tick,
980985
max_rotations,
981986
max_bytes_per_file,

0 commit comments

Comments
 (0)