Skip to content

Commit

Permalink
Keep derive_default_enum feature and add rusty-fork
Browse files Browse the repository at this point in the history
  • Loading branch information
ileixe committed Jul 5, 2022
1 parent 8fd8526 commit 99de570
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 67 deletions.
31 changes: 29 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracing-chrometrace"
version = "0.1.16"
version = "0.1.17"
edition = "2018"

authors = ["Youseok Yang <[email protected]>"]
Expand All @@ -21,8 +21,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = { version = "0.22", features = ["derive"] }
strum_macros = "0.22"
temp-file = "0.1.7"
tempfile = "3.3.0"

tracing = "0.1.34"
tracing-subscriber = { version = "0.3.11", features = ["fmt", "std", "env-filter"] }
Expand All @@ -32,6 +30,8 @@ criterion = { version = "0.3", features = ["html_reports"] }
crossbeam-queue = "0.3.5"
tracing-appender = "0.2.2"
tracing-chrome = "0.5.0"
temp-file = "0.1.7"
rusty-fork = "0.3.0"

[[bench]]
name = "benchmark"
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! tracing_subscriber::registry().with(writer).init();
//! ```
#![feature(derive_default_enum)]
#![feature(thread_id_value)]

use std::borrow::Cow;
Expand Down
125 changes: 63 additions & 62 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,78 +1,79 @@
use itertools::Itertools;
use std::{
fs::{self, File},
thread,
time::Duration,
};
use tempfile;
use rusty_fork::rusty_fork_test;

use tracing_appender::non_blocking::NonBlocking;
use tracing_chrometrace::{ChromeEvent, ChromeLayer};
use tracing_subscriber::prelude::*;

#[test]
fn test_init() {
let (writer, _guard) = ChromeLayer::with_writer(std::io::stdout);

tracing_subscriber::registry().with(writer).init();
rusty_fork_test! {
#[test]
fn test_init() {
let (writer, _guard) = ChromeLayer::with_writer(std::io::stdout);

tracing::info!(target = "chrome_layer", message = "hello");
}

#[test]
fn test_concurrent_write() {
let file = temp_file::empty();
let (writer, worker) = NonBlocking::new(File::create(file.path()).unwrap());
let (writer, guard) = ChromeLayer::with_writer(writer);

let iterations = 1000;

tracing_subscriber::registry().with(writer).init();

let handle = thread::spawn(move || {
for i in 0..iterations {
tracing::info!(thread = 0, index = i);
}
});

let handle2 = thread::spawn(move || {
for i in 0..iterations {
tracing::info!(thread = 1, index = i);
}
});
tracing_subscriber::registry().with(writer).init();

let handle3 = thread::spawn(move || {
for i in 0..iterations {
tracing::info!(thread = 2, index = i);
}
});
tracing::info!(target = "chrome_layer", message = "hello");
}

let handle4 = thread::spawn(move || {
for i in 0..iterations {
tracing::info!(thread = 3, index = i);
#[test]
fn test_concurrent_write() {
let file = temp_file::empty();
let (writer, worker) = NonBlocking::new(File::create(file.path()).unwrap());
let (writer, guard) = ChromeLayer::with_writer(writer);

let iterations = 1000;

tracing_subscriber::registry().with(writer).init();

let handle = thread::spawn(move || {
for i in 0..iterations {
tracing::info!(thread = 0, index = i);
}
});

let handle2 = thread::spawn(move || {
for i in 0..iterations {
tracing::info!(thread = 1, index = i);
}
});

let handle3 = thread::spawn(move || {
for i in 0..iterations {
tracing::info!(thread = 2, index = i);
}
});

let handle4 = thread::spawn(move || {
for i in 0..iterations {
tracing::info!(thread = 3, index = i);
}
});

handle.join().unwrap();
handle2.join().unwrap();
handle3.join().unwrap();
handle4.join().unwrap();

drop(guard);
drop(worker);

let events = fs::read_to_string(file.path()).unwrap();
let events: Vec<ChromeEvent> = serde_json::from_str::<Vec<ChromeEvent>>(&events).unwrap();

let expected: Vec<i32> = (0..iterations).collect();

for i in 0..4 {
let found: Vec<i32> = events
.iter()
.filter(|e| e.args["thread"] == i.to_string())
.map(|e| e.args["index"].parse().unwrap())
.collect();

assert_eq!(expected, found)
}
});

handle.join();
handle2.join();
handle3.join();
handle4.join();

drop(guard);
drop(worker);

let events = fs::read_to_string(file.path()).unwrap();
let events: Vec<ChromeEvent> = serde_json::from_str::<Vec<ChromeEvent>>(&events).unwrap();

let expected: Vec<i32> = (0..iterations).collect();

for i in 0..4 {
let found: Vec<i32> = events
.iter()
.filter(|e| e.args["thread"] == i.to_string())
.map(|e| e.args["index"].parse().unwrap())
.collect();

assert_eq!(expected, found)
}
}

0 comments on commit 99de570

Please sign in to comment.