From cc164b5e53cf5214397d4d72bdf67f5f487798d3 Mon Sep 17 00:00:00 2001 From: Yehor KOROTENKO <60360745+DobbiKov@users.noreply.github.com> Date: Wed, 4 Jun 2025 12:30:06 +0200 Subject: [PATCH] Improve rotation test to confirm new log --- tests/archivation_rotation.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/archivation_rotation.rs b/tests/archivation_rotation.rs index 4bb357f..ee19f87 100644 --- a/tests/archivation_rotation.rs +++ b/tests/archivation_rotation.rs @@ -14,8 +14,8 @@ use loggit::{ Level, }; -/// We rotate after 1 KB, so a few thousand reasonably long messages are plenty. -const MESSAGES: usize = 2_000; +/// We rotate after 1 KB, so a few hundred reasonably long messages are plenty. +const MESSAGES: usize = 50; #[test] fn rotation_creates_zip_archive() { @@ -42,9 +42,14 @@ fn rotation_creates_zip_archive() { for n in 0..MESSAGES { info!("msg {n}: lorem ipsum dolor sit amet, consectetur adipiscing elit."); } + // One more message so a new log file gets created after rotation. + info!("post-rotation message"); // Tiny wait to make sure the last write flushed & compression finished. thread::sleep(Duration::from_millis(50)); + // And another log entry to guarantee the new file exists on disk. + info!("post-check message"); + thread::sleep(Duration::from_millis(50)); // Assert: at least one .zip archive exists in the archive directory. let mut zip_found = false; @@ -60,6 +65,20 @@ fn rotation_creates_zip_archive() { } assert!(zip_found, "no .zip archive produced after rotation"); + // Assert: rotation should leave a new active log file. + let mut log_found = false; + for entry in fs::read_dir(".").unwrap() { + let p = entry.unwrap().path(); + if p.file_name() + .and_then(|n| n.to_str()) + .map(|n| n.starts_with(&prefix) && n.ends_with(".log")) + .unwrap_or(false) + { + log_found = true; + } + } + assert!(log_found, "rotation did not produce a new active log file"); + // ───── clean‑up ──────────────────────────────────────────────────────────── // remove generated log files for entry in fs::read_dir(".").unwrap() {