Skip to content

Commit

Permalink
fix: pactffi_mock_server_logs empty due to tracing lib mismatch
Browse files Browse the repository at this point in the history
add smoke test, needs to be executed in isolation, as it uses the global logging provider and thusly is affected by other tests in the same process
  • Loading branch information
YOU54F committed Jun 8, 2024
1 parent 5699cab commit 5fec932
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 31 additions & 2 deletions rust/pact_ffi/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,14 +21,14 @@ use tempfile::TempDir;
use serde_json::{json, Value};
use rstest::rstest;
use regex::Regex;

#[allow(deprecated)]
use pact_ffi::mock_server::{
pactffi_cleanup_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::{
Expand Down Expand Up @@ -1406,3 +1408,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);
}
4 changes: 2 additions & 2 deletions rust/pact_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions rust/scripts/ci-musl-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ set -ex
rustc --print cfg
cargo build
cargo test
cargo test -p pact_ffi returns_mock_server_logs -- --nocapture --include-ignored

0 comments on commit 5fec932

Please sign in to comment.