-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
148 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#[cfg(test)] | ||
mod test { | ||
use std::thread::sleep; | ||
use std::time::{Duration, Instant}; | ||
|
||
use log::{debug, info, Level}; | ||
use log::error; | ||
|
||
use crate::{init_custom_log, init_log, init_split_log}; | ||
use crate::bencher::QPS; | ||
use crate::consts::LogSize; | ||
use crate::filter::NoFilter; | ||
use crate::plugin::file_split::RollingType; | ||
use crate::appender::{FastLogFormatRecord, LogAppender, FastLogRecord}; | ||
|
||
#[test] | ||
pub fn test_log() { | ||
init_log("requests.log", 1000, log::Level::Debug, None, true); | ||
debug!("Commencing yak shaving{}", 0); | ||
sleep(Duration::from_secs(1)); | ||
} | ||
|
||
//cargo test --release --color=always --package fast_log --lib fast_log::test::bench_log --no-fail-fast -- --exact -Z unstable-options --show-output | ||
#[test] | ||
pub fn bench_log() { | ||
init_log("requests.log", 1000, log::Level::Info, None, false); | ||
let total = 10000; | ||
let now = Instant::now(); | ||
for index in 0..total { | ||
//sleep(Duration::from_secs(1)); | ||
info!("Commencing yak shaving{}", index); | ||
} | ||
now.time(total); | ||
now.qps(total); | ||
sleep(Duration::from_secs(1)); | ||
} | ||
|
||
struct CustomLog {} | ||
|
||
impl LogAppender for CustomLog { | ||
fn do_log(&self, record: &FastLogRecord) { | ||
let data; | ||
match record.level { | ||
Level::Warn | Level::Error => { | ||
data = format!("{} {} {} - {} {}\n", &record.now, record.level, record.module_path, record.args, record.format_line()); | ||
} | ||
_ => { | ||
data = format!("{} {} {} - {}\n", &record.now, record.level, record.module_path, record.args); | ||
} | ||
} | ||
print!("{}", data); | ||
} | ||
} | ||
|
||
#[test] | ||
pub fn test_custom() { | ||
init_custom_log(vec![Box::new(CustomLog {})], 1000, log::Level::Info, Box::new(NoFilter {}),Box::new(FastLogFormatRecord{})); | ||
info!("Commencing yak shaving"); | ||
error!("Commencing error"); | ||
sleep(Duration::from_secs(1)); | ||
} | ||
|
||
#[test] | ||
pub fn test_file_compation() { | ||
init_split_log("target/logs/", 1000, LogSize::MB(1), false, RollingType::All, log::Level::Info, None, true); | ||
for _ in 0..20000 { | ||
info!("Commencing yak shaving"); | ||
} | ||
sleep(Duration::from_secs(1)); | ||
} | ||
|
||
#[test] | ||
pub fn test_file_compation_zip() { | ||
init_split_log("target/logs/", 1000, LogSize::KB(50), true, RollingType::KeepNum(5), log::Level::Info, None, true); | ||
for _ in 0..20000 { | ||
info!("Commencing yak shaving"); | ||
} | ||
sleep(Duration::from_secs(10)); | ||
} | ||
|
||
#[test] | ||
pub fn test_file_compation_zip_stable_test() { | ||
init_split_log("target/logs/", 1000, LogSize::MB(100), true, RollingType::All, log::Level::Info, None, false); | ||
let now = std::time::Instant::now(); | ||
loop { | ||
info!("Commencing yak shaving"); | ||
if now.elapsed() > Duration::from_secs(30) { | ||
break; | ||
} | ||
} | ||
info!("done"); | ||
sleep(Duration::from_secs(100)); | ||
} | ||
|
||
|
||
struct BenchRecvLog {} | ||
|
||
impl LogAppender for BenchRecvLog { | ||
fn do_log(&self, record: &FastLogRecord) {} | ||
} | ||
|
||
//cargo test --release --color=always --package fast_log --lib fast_log::test::bench_recv --no-fail-fast -- --exact -Z unstable-options --show-output | ||
#[test] | ||
pub fn bench_recv() { | ||
init_custom_log(vec![Box::new(BenchRecvLog {})], 1000, log::Level::Info, Box::new(NoFilter {}),Box::new(FastLogFormatRecord{})); | ||
let total = 10000; | ||
let now = Instant::now(); | ||
for index in 0..total { | ||
//sleep(Duration::from_secs(1)); | ||
info!("Commencing yak shaving{}", index); | ||
} | ||
now.time(total); | ||
now.qps(total); | ||
sleep(Duration::from_secs(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod fast_log_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters