From 19957df513d5d32f02ca462b014a13fe2f09aa30 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Tue, 11 Jun 2024 16:00:04 +1000 Subject: [PATCH] chore: Lock tracing crates to the same version via cargo patch block --- .github/workflows/build.yml | 6 ++++++ compatibility-suite/Cargo.toml | 6 +++--- rust/Cargo.lock | 28 +++++++++++++++++----------- rust/Cargo.toml | 4 ++++ rust/pact_ffi/tests/tests.rs | 32 +++++++++++++++++++++++++++++++- rust/pact_models/Cargo.toml | 4 ++-- 6 files changed, 63 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cfa567238..3a69d4002 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,6 +27,12 @@ jobs: env: RUST_LOG: debug RUST_BACKTRACE: 1 + - name: Run mock_server_logs test + run: cargo test -p pact_ffi returns_mock_server_logs -- --nocapture --include-ignored + working-directory: rust + env: + RUST_LOG: debug + RUST_BACKTRACE: 1 - name: Build Components run: cargo build working-directory: rust diff --git a/compatibility-suite/Cargo.toml b/compatibility-suite/Cargo.toml index bd4408e2f..3b525a719 100644 --- a/compatibility-suite/Cargo.toml +++ b/compatibility-suite/Cargo.toml @@ -15,7 +15,7 @@ lazy_static = "1.4.0" maplit = "1.0.2" pact_models = { version = "~1.2.0" } pact_matching = { version = "1.2.3", path = "../rust/pact_matching" } -pact_mock_server = { version = "1.2.8" } +pact_mock_server = { version = "1.2.9" } pact_verifier = { version = "1.2.1", path = "../rust/pact_verifier" } pact_consumer = { version = "1.2.0", path = "../rust/pact_consumer" } pretty_assertions = "1.4.0" @@ -26,8 +26,8 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.108" sxd-document = "0.3.2" tokio = { version = "1.33.0", features = ["full"] } -tracing = "0.1.40" -tracing-subscriber = { version = "0.3.17", features = ["env-filter", "tracing-log", "fmt"] } +tracing = "=0.1.40" +tracing-subscriber = { version = "=0.3.18", features = ["env-filter", "tracing-log", "fmt"] } uuid = { version = "1.5.0", features = ["v4"] } [[test]] diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 8681cdd81..45f942f14 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -2120,7 +2120,7 @@ dependencies = [ "tokio-rustls 0.24.1", "tracing", "tracing-core", - "tracing-log", + "tracing-log 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tracing-subscriber", "uuid", "zeroize", @@ -2394,7 +2394,7 @@ dependencies = [ "tokio", "tracing", "tracing-core", - "tracing-log", + "tracing-log 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tracing-subscriber", "trycmd", ] @@ -3858,8 +3858,7 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +source = "git+https://github.com/tokio-rs/tracing.git?tag=tracing-subscriber-0.3.18#8b7a1dde69797b33ecfa20da71e72eb5e61f0b25" dependencies = [ "log", "pin-project-lite", @@ -3870,8 +3869,7 @@ dependencies = [ [[package]] name = "tracing-attributes" version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +source = "git+https://github.com/tokio-rs/tracing.git?tag=tracing-subscriber-0.3.18#8b7a1dde69797b33ecfa20da71e72eb5e61f0b25" dependencies = [ "proc-macro2 1.0.85", "quote 1.0.36", @@ -3881,8 +3879,7 @@ dependencies = [ [[package]] name = "tracing-core" version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +source = "git+https://github.com/tokio-rs/tracing.git?tag=tracing-subscriber-0.3.18#8b7a1dde69797b33ecfa20da71e72eb5e61f0b25" dependencies = [ "once_cell", "valuable", @@ -3899,11 +3896,20 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "git+https://github.com/tokio-rs/tracing.git?tag=tracing-subscriber-0.3.18#8b7a1dde69797b33ecfa20da71e72eb5e61f0b25" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +source = "git+https://github.com/tokio-rs/tracing.git?tag=tracing-subscriber-0.3.18#8b7a1dde69797b33ecfa20da71e72eb5e61f0b25" dependencies = [ "matchers", "nu-ansi-term", @@ -3914,7 +3920,7 @@ dependencies = [ "thread_local", "tracing", "tracing-core", - "tracing-log", + "tracing-log 0.2.0 (git+https://github.com/tokio-rs/tracing.git?tag=tracing-subscriber-0.3.18)", ] [[package]] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 7edfa2db9..daa43045a 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,6 +11,10 @@ resolver = "2" [patch.crates-io] # Waiting on the next release of Onig crate onig = { git = "https://github.com/rust-onig/rust-onig", default-features = false, rev = "76bc1d29651bd17c7d5ecea9266bd2e0e83cb2e0" } +# This needs to be the same version across all the libs (i.e. Pact FFI and plugin driver) +tracing = { git = "https://github.com/tokio-rs/tracing.git", tag = "tracing-subscriber-0.3.18" } +tracing-core = { git = "https://github.com/tokio-rs/tracing.git", tag = "tracing-subscriber-0.3.18" } +tracing-subscriber = { git = "https://github.com/tokio-rs/tracing.git", tag = "tracing-subscriber-0.3.18" } [profile.release] strip = true diff --git a/rust/pact_ffi/tests/tests.rs b/rust/pact_ffi/tests/tests.rs index 1f0ce774d..5f6a63054 100644 --- a/rust/pact_ffi/tests/tests.rs +++ b/rust/pact_ffi/tests/tests.rs @@ -9,7 +9,9 @@ use bytes::Bytes; use expectest::prelude::*; use itertools::Itertools; use libc::c_char; +use log::LevelFilter; use maplit::*; +use pact_ffi::log::pactffi_log_to_buffer; use pact_models::bodies::OptionalBody; use pact_models::PactSpecification; use pretty_assertions::assert_eq; @@ -26,7 +28,8 @@ use pact_ffi::mock_server::{ pactffi_create_mock_server, pactffi_create_mock_server_for_pact, pactffi_mock_server_mismatches, - pactffi_write_pact_file + pactffi_write_pact_file, + pactffi_mock_server_logs, }; #[allow(deprecated)] use pact_ffi::mock_server::handles::{ @@ -1406,3 +1409,30 @@ fn matching_definition_expressions_matcher() { } }; } + +// Run independently as this log settings are global, and other tests affect this one. +// cargo test -p pact_ffi returns_mock_server_logs -- --nocapture --include-ignored +#[ignore] +#[test] +fn returns_mock_server_logs() { + let pact_json = include_str!("post-pact.json"); + let pact_json_c = CString::new(pact_json).expect("Could not construct C string from json"); + let address = CString::new("127.0.0.1:0").unwrap(); + #[allow(deprecated)] + let port = pactffi_create_mock_server(pact_json_c.as_ptr(), address.as_ptr(), false); + expect!(port).to(be_greater_than(0)); + pactffi_log_to_buffer(LevelFilter::Debug.into()); + let client = Client::default(); + client.post(format!("http://127.0.0.1:{}/path", port).as_str()) + .header(CONTENT_TYPE, "application/json") + .body(r#"{"foo":"no-very-bar"}"#) + .send().expect("Sent POST request to mock server"); + + let logs = unsafe { + CStr::from_ptr(pactffi_mock_server_logs(port)).to_string_lossy().into_owned() + }; + println!("{}",logs); + assert_ne!(logs,"", "logs are empty"); + + pactffi_cleanup_mock_server(port); +} \ No newline at end of file diff --git a/rust/pact_models/Cargo.toml b/rust/pact_models/Cargo.toml index 0235a603b..84bcb0eb1 100644 --- a/rust/pact_models/Cargo.toml +++ b/rust/pact_models/Cargo.toml @@ -45,7 +45,7 @@ semver = "1.0.17" serde = { version = "1.0.163", features = ["derive"] } serde_json = "1.0.96" sxd-document = { version = "0.3.2", optional = true } -tracing = "0.1.37" # This needs to be the same version across all the libs (i.e. Pact FFI and plugin driver) +tracing = "0.1.40" # This needs to be the same version across all the libs (i.e. Pact FFI and plugin driver) [target.'cfg(not(target_family = "wasm"))'.dependencies] fs2 = "0.4.3" @@ -64,7 +64,7 @@ pretty_assertions = "1.3.0" rstest = "0.19.0" speculate = "0.1.2" test-log = { version = "0.2.11", features = ["trace"] } -tracing-subscriber = { version = "0.3.16", features = ["env-filter", "tracing-log", "fmt"] } +tracing-subscriber = { version = "0.3.18", features = ["env-filter", "tracing-log", "fmt"] } trim-margin = "0.1.0" [build-dependencies]