Skip to content

Commit

Permalink
fix(tester): re-apply MacOS CI fix (commit 6fde964)
Browse files Browse the repository at this point in the history
Reapply 6fde964 (fix(tester): make human rule trace writer blocking,
2025-01-08)

PR #569 accidentally reverted this change, causing ACCEPT=true failures
on my Mac and some CI failures.

This commit also adds the previous fix to the new JSON logging layer.
  • Loading branch information
niklasdewally committed Jan 20, 2025
1 parent 9c3ccbb commit 5f986f9
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions conjure_oxide/tests/generated_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::expect_used)]

use conjure_core::rule_engine::rewrite_naive;
use conjure_core::Model;
use conjure_oxide::utils::essence_parser::parse_essence_file_native;
Expand All @@ -16,8 +18,6 @@ use tracing_subscriber::{

use uniplate::Biplate;

use tracing_appender::non_blocking::WorkerGuard;

use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;
Expand Down Expand Up @@ -99,7 +99,7 @@ fn integration_test(path: &str, essence_base: &str, extension: &str) -> Result<(
// run tests in sequence not parallel when verbose logging, to ensure the logs are ordered
// correctly

let (subscriber, _guards) = create_scoped_subscriber(path, essence_base);
let subscriber = create_scoped_subscriber(path, essence_base);

// set the subscriber as default
tracing::subscriber::with_default(subscriber, || {
Expand Down Expand Up @@ -392,60 +392,48 @@ fn assert_constants_leq_one(parent_expr: &Expression, exprs: &[Expression]) {
pub fn create_scoped_subscriber(
path: &str,
test_name: &str,
) -> (
impl tracing::Subscriber + Send + Sync,
Vec<tracing_appender::non_blocking::WorkerGuard>,
) {
let (target1_layer, guard1) = create_file_layer_json(path, test_name);
let (target2_layer, guard2) = create_file_layer_human(path, test_name);
) -> (impl tracing::Subscriber + Send + Sync) {
let target1_layer = create_file_layer_json(path, test_name);
let target2_layer = create_file_layer_human(path, test_name);
let layered = target1_layer.and_then(target2_layer);

let subscriber = Arc::new(tracing_subscriber::registry().with(layered))
as Arc<dyn tracing::Subscriber + Send + Sync>;
// setting this subscriber as the default
let _default = tracing::subscriber::set_default(subscriber.clone());

(subscriber, vec![guard1, guard2])
subscriber
}

fn create_file_layer_json(
path: &str,
test_name: &str,
) -> (impl Layer<Registry> + Send + Sync, WorkerGuard) {
fn create_file_layer_json(path: &str, test_name: &str) -> impl Layer<Registry> + Send + Sync {
let file = File::create(format!("{path}/{test_name}-generated-rule-trace.json"))
.expect("Unable to create log file");
let (non_blocking, guard1) = tracing_appender::non_blocking(file);

let layer1 = fmt::layer()
.with_writer(non_blocking)
.with_writer(file)
.with_level(false)
.with_target(false)
.without_time()
.with_filter(FilterFn::new(|meta: &OtherMetadata| {
meta.target() == "rule_engine"
}));

(layer1, guard1)
layer1
}

fn create_file_layer_human(
path: &str,
test_name: &str,
) -> (impl Layer<Registry> + Send + Sync, WorkerGuard) {
fn create_file_layer_human(path: &str, test_name: &str) -> (impl Layer<Registry> + Send + Sync) {
let file = File::create(format!("{path}/{test_name}-generated-rule-trace-human.txt"))
.expect("Unable to create log file");

let (non_blocking, guard2) = tracing_appender::non_blocking(file);

let layer2 = fmt::layer()
.with_writer(non_blocking)
.with_writer(file)
.with_level(false)
.without_time()
.with_target(false)
.with_filter(EnvFilter::new("rule_engine_human=trace"))
.with_filter(FilterFn::new(|meta| meta.target() == "rule_engine_human"));

(layer2, guard2)
layer2
}

#[test]
Expand Down

0 comments on commit 5f986f9

Please sign in to comment.