Skip to content

Commit

Permalink
Fix the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
1996fanrui committed Aug 10, 2024
1 parent 53b5bf7 commit f0cfc57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/append/rolling_file/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ impl Clock for DefaultClock {

/// The time could be reset.
#[derive(Debug)]
#[cfg(test)]
pub struct ManualClock {
fixed_time: OffsetDateTime,
}

#[cfg(test)]
impl Clock for ManualClock {
fn now(&self) -> OffsetDateTime {
self.fixed_time
}
}

#[cfg(test)]
impl ManualClock {
pub fn new(fixed_time: OffsetDateTime) -> ManualClock {
ManualClock { fixed_time }
Expand All @@ -54,17 +57,20 @@ impl ManualClock {
#[derive(Debug)]
pub enum StateClock {
DefaultClock(DefaultClock),
#[cfg(test)]
ManualClock(ManualClock),
}

impl StateClock {
pub fn now(&self) -> OffsetDateTime {
match self {
StateClock::DefaultClock(clock) => clock.now(),
#[cfg(test)]
StateClock::ManualClock(clock) => clock.now(),
}
}

#[cfg(test)]
pub fn set_now(&mut self, new_time: OffsetDateTime) {
if let StateClock::ManualClock(clock) = self {
clock.set_now(new_time);
Expand Down
10 changes: 4 additions & 6 deletions src/append/rolling_file/rolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::io::Write;
use std::path::Path;
use std::path::PathBuf;

use crate::append::rolling_file::clock::{Clock, DefaultClock, StateClock};
use crate::append::rolling_file::clock::{DefaultClock, StateClock};
use crate::append::rolling_file::TimeRotation;
use anyhow::Context;
use parking_lot::RwLock;
Expand Down Expand Up @@ -137,6 +137,7 @@ impl RollingFileWriterBuilder {
self
}

#[cfg(test)]
fn clock(mut self, clock: StateClock) -> Self {
self.clock = Some(clock);
self
Expand All @@ -159,7 +160,7 @@ impl RollingFileWriterBuilder {
suffix,
max_size,
max_files,
clock.unwrap_or_else(|| StateClock::DefaultClock(DefaultClock)),
clock.unwrap_or(StateClock::DefaultClock(DefaultClock)),
)?;
Ok(RollingFileWriter { state, writer })
}
Expand Down Expand Up @@ -423,7 +424,6 @@ mod tests {
) {
let temp_dir = TempDir::new().expect("failed to create a temporary directory");
let max_files = 10;
let max_size = 1000000;

let start_time = datetime!(2024-08-10 00:00:00 +0);
let mut writer = RollingFileWriterBuilder::new()
Expand All @@ -432,9 +432,7 @@ mod tests {
.filename_suffix("log")
.max_log_files(max_files)
.max_file_size(usize::MAX)
.clock(StateClock::ManualClock(ManualClock::new(
start_time.clone(),
)))
.clock(StateClock::ManualClock(ManualClock::new(start_time)))
.build(&temp_dir)
.unwrap();

Expand Down

0 comments on commit f0cfc57

Please sign in to comment.