Skip to content

Commit

Permalink
Update onstartup.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirreke authored Feb 11, 2024
1 parent a4d21f0 commit 4351c83
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/append/rolling_file/policy/compound/trigger/onstartup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ impl OnStartUpTrigger {

impl Trigger for OnStartUpTrigger {
fn trigger(&self, file: &LogFile) -> anyhow::Result<bool> {
if !self.initial.is_completed() {
self.initial.call_once(|| {});
let mut result = false;
self.initial.call_once(|| {
if file.len_estimate() >= self.min_size {
return Ok(true);
result = true;
}
}
Ok(false)
});
Ok(result)
}

fn is_pre_process(&self) -> bool {
Expand Down Expand Up @@ -94,7 +94,7 @@ mod test {
}

#[test]
fn trigger1() {
fn trigger() {
let file = tempfile::tempdir().unwrap();
let logfile = LogFile {
writer: &mut None,
Expand All @@ -104,23 +104,13 @@ mod test {

let trigger = OnStartUpTrigger::new(1);
let result = trigger.trigger(&logfile).unwrap();
assert_eq!(result, false);
}

#[test]
fn trigger2() {
let file = tempfile::tempdir().unwrap();
let logfile = LogFile {
writer: &mut None,
path: file.path(),
len: 0,
};
assert_eq!(result, false); // It should not be triggered with the min_size 1.

let trigger = OnStartUpTrigger::new(0);
let result = trigger.trigger(&logfile).unwrap();
assert_eq!(result, true);
assert_eq!(result, true); // First time, it should be triggered.

let result = trigger.trigger(&logfile).unwrap();
assert_eq!(result, false);
assert_eq!(result, false); // Second time, it should not be triggered.
}
}

0 comments on commit 4351c83

Please sign in to comment.