Skip to content

Commit

Permalink
Run externalized tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom committed Mar 1, 2025
1 parent 957cffc commit 6223c18
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ concurrency:
cancel-in-progress: true

jobs:
ext-test:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install Rust stable toolchain
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain stable
rustup override set stable
- name: Run externalized tests
run: |
cd ext-functional-test-demo
cargo test --verbose --color always
cargo test --verbose --color always --features test-broken
build:
strategy:
fail-fast: false
Expand Down
7 changes: 0 additions & 7 deletions ci/ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ cargo check --verbose --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

echo -e "\n\Running functional tests from outside the workspace"
pushd ext-functional-test-demo
[ "$RUSTC_MINOR_VERSION" -lt 65 ] && cargo update -p regex --precise "1.9.6" --verbose
cargo test --color always
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
popd

# Test that we can build downstream code with only the "release pins".
pushd msrv-no-dev-deps-check
PIN_RELEASE_DEPS
Expand Down
3 changes: 3 additions & 0 deletions ext-functional-test-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ name = "ext-functional-tester"
version = "0.1.0"
edition = "2021"

[features]
test-broken = []

[dependencies]
lightning = { path = "../lightning", features = ["_externalize_tests"] }
40 changes: 35 additions & 5 deletions ext-functional-test-demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ fn main() {
}

#[cfg(test)]
#[allow(unused)]
mod tests {
use lightning::ln::functional_tests::*;
use lightning::util::dyn_signer::{DynKeysInterfaceTrait, DynSigner};
use lightning::util::test_utils::{TestSignerFactory, SIGNER_FACTORY};
use std::panic::catch_unwind;
Expand All @@ -20,12 +22,40 @@ mod tests {
}
}

#[cfg(feature = "test-broken")]
#[test]
fn test_functional() {
lightning::ln::functional_tests::test_insane_channel_opens();
lightning::ln::functional_tests::fake_network_test();

fn test_broken() {
SIGNER_FACTORY.set(Arc::new(BrokenSignerFactory()));
catch_unwind(|| lightning::ln::functional_tests::fake_network_test()).unwrap_err();
catch_unwind(|| fake_network_test()).unwrap_err();
}

#[cfg(not(feature = "test-broken"))]
#[test]
fn test_default_one() {
test_htlc_on_chain_success();
}

#[cfg(not(feature = "test-broken"))]
#[test]
fn test_default_all() {
let mut failed_tests = Vec::new();
for test in lightning::get_xtests() {
print!("Running test: {}", test.test_name);
let mut pass = catch_unwind(|| (test.test_fn)()).is_ok();
if test.should_panic {
pass = !pass;
}
if !pass {
failed_tests.push(test.test_name);
}
}
if !failed_tests.is_empty() {
println!("Failed tests:");
for test in failed_tests.iter() {
println!("- {}", test);
}
}
println!("Done with {} failures", failed_tests.len());
assert!(failed_tests.is_empty());
}
}

0 comments on commit 6223c18

Please sign in to comment.