diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 5c0c135f7e..330e1f2b7b 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -15,7 +15,7 @@ jobs: name: Unit Tests env: # `-D warnings` means any warnings emitted will cause build to fail - RUSTFLAGS: "-D warnings -C opt-level=z -C target-cpu=x86-64 -C debuginfo=1" + RUSTFLAGS: "-C opt-level=z -C target-cpu=x86-64 -C debuginfo=1" X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR: c:/vcpkg/installed/x64-windows runs-on: ${{ matrix.os }} strategy: @@ -48,7 +48,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --all-targets --all-features --workspace -- -D warnings + args: --all-targets --all-features --workspace - name: Install openssl ( Windows only ) if: runner.os == 'Windows' diff --git a/Cargo.toml b/Cargo.toml index 9fcc222940..41300a350e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -227,5 +227,9 @@ web3 = { git = "https://github.com/golemfactory/rust-web3", branch = "update_eth # Speed up builds on macOS (will be default in next rust version probably) # https://jakedeichert.com/blog/reducing-rust-incremental-compilation-times-on-macos-by-70-percent/ -[profile.dev] -split-debuginfo = "unpacked" +# +# TODO: reenable split-debuginfo. +# Commented out split-debuginfo makes Windows builds fail due to "`-Csplit-debuginfo=unpacked` is unstable on this platform." +# This should not be the case (cargo is meant to verify that this option is supported), but it is since version 1.65, I think. +# [profile.dev] +# split-debuginfo = "unpacked" diff --git a/core/market/src/testing/backtrace_util.rs b/core/market/src/testing/backtrace_util.rs index b79db2d74e..ee3b3016fc 100644 --- a/core/market/src/testing/backtrace_util.rs +++ b/core/market/src/testing/backtrace_util.rs @@ -21,7 +21,7 @@ fn adjust_backtrace_level(frames: &[backtrace::BacktraceFrame]) -> Option } fn get_symbol_at_level(bt: &backtrace::Backtrace, lvl: usize) -> Option { - let frames = &bt.frames(); + let frames = bt.frames(); match adjust_backtrace_level(frames) { Some(adjustment) => { let frame = &frames[lvl + adjustment]; @@ -34,18 +34,17 @@ fn get_symbol_at_level(bt: &backtrace::Backtrace, lvl: usize) -> Option None } -pub fn generate_backtraced_name(level: Option) -> String { +pub fn generate_backtraced_name(level: Option) -> Option { let bt = backtrace::Backtrace::new(); + // 0th element should be this function. We'd like to know the caller - if let Some(name) = get_symbol_at_level(&bt, level.unwrap_or(1)) { + let name = get_symbol_at_level(&bt, level.unwrap_or(1)); + + if let Some(name) = &name { log::trace!("Generated name: {} level: {:?} BT: {:#?}", name, level, bt); - return name; + } else { + log::warn!("No backtrace support. bt={:#?}", bt); } - let u4 = uuid::Uuid::new_v4().to_string(); - log::error!( - "No backtrace support. Generating default name from UUIDv4. uuid4={}, bt={:#?}", - u4, - bt - ); - u4 + + name } diff --git a/core/market/src/testing/mock_node.rs b/core/market/src/testing/mock_node.rs index 2477c08a4e..d82f60021d 100644 --- a/core/market/src/testing/mock_node.rs +++ b/core/market/src/testing/mock_node.rs @@ -105,14 +105,14 @@ impl MockNodeKind { } } -fn testname_from_backtrace(bn: &str) -> String { +fn testname_from_backtrace(bn: &str) -> Option { log::info!("Test name to regex match: {}", &bn); // Extract test name - let captures = Regex::new(r"(.*)::(.*)::.*").unwrap().captures(bn).unwrap(); + let captures = Regex::new(r"(.*)::(.*)::.*").unwrap().captures(bn)?; let filename = captures.get(1).unwrap().as_str().to_string(); let testname = captures.get(2).unwrap().as_str().to_string(); - format!("{}.{}", filename, testname) + Some(format!("{}.{}", filename, testname)) } impl MarketsNetwork { @@ -122,19 +122,35 @@ impl MarketsNetwork { pub async fn new(test_name: Option<&str>) -> Self { std::env::set_var("RUST_LOG", "debug"); let _ = env_logger::builder().try_init(); - // level 1 is this function. - // level 2 is as - // core::future::future::Future>::poll::XXX> (async) - // We want to know the caller. - let mut bn = crate::testing::backtrace_util::generate_backtraced_name(Some(3)); - // Special case for mac&windows. Tests are run in adifferent way on those systems and we - // have to dive one less level down the stack to find the caller (test_* module). - if !bn.starts_with("test_") { - bn = crate::testing::backtrace_util::generate_backtraced_name(Some(2)); - } - bn = testname_from_backtrace(&bn); - let test_name = test_name.unwrap_or(&bn).to_string(); + let test_name_from_bt = || { + // level 1 is this function. + // level 2 is as + // core::future::future::Future>::poll::XXX> (async) + // We want to know the caller. + crate::testing::backtrace_util::generate_backtraced_name(Some(3)) + .and_then(|name| { + // Special case for mac&windows. Tests are run in adifferent way on those systems and we + // have to dive one less level down the stack to find the caller (test_* module). + if !name.starts_with("test_") { + crate::testing::backtrace_util::generate_backtraced_name(Some(2)) + } else { + Some(name) + } + }) + .as_deref() + .and_then(testname_from_backtrace) + }; + + let unknown_test_name = || { + let nonce = rand::random::(); + format!("unknown-test-{:#32x}", nonce) + }; + + let test_name = test_name + .map(String::from) + .or_else(test_name_from_bt) + .unwrap_or_else(unknown_test_name); log::info!("Intializing MarketsNetwork. tn={}", test_name); MockNet::default().bind_gsb();