From 48bc9ed0269ad9ef7a3547bf586d59b67673ff14 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Fri, 5 Jul 2024 13:48:17 +0530 Subject: [PATCH] fix(ci): run spend simulation as its own test --- .github/workflows/merge.yml | 65 ++++++++++++++++++++++++++++++- .github/workflows/nightly.yml | 65 +++++++++++++++++++++++++++++-- sn_node/tests/spend_simulation.rs | 2 +- 3 files changed, 126 insertions(+), 6 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index deb9622df1..3215bb3057 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -359,7 +359,7 @@ jobs: timeout-minutes: 30 - name: Build testing executable - run: cargo test --release -p sn_node --features=local-discovery --test sequential_transfers --test storage_payments --test double_spend --test spend_simulation --no-run + run: cargo test --release -p sn_node --features=local-discovery --test sequential_transfers --test storage_payments --test double_spend --no-run env: # only set the target dir for windows to bypass the linker issue. # happens if we build the node manager via testnet action @@ -406,6 +406,67 @@ jobs: CARGO_TARGET_DIR: ${{ matrix.os == 'windows-latest' && './test-target' || '.' }} timeout-minutes: 25 + - name: Stop the local network and upload logs + if: always() + uses: maidsafe/sn-local-testnet-action@main + with: + action: stop + log_file_prefix: safe_test_logs_spend + platform: ${{ matrix.os }} + + # runs with increased node count + spend_simulation: + if: "!startsWith(github.event.head_commit.message, 'chore(release):')" + name: spend simulation + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + + - uses: Swatinem/rust-cache@v2 + + - name: Build binaries + run: cargo build --release --features=local-discovery --bin safenode + timeout-minutes: 30 + + - name: Build faucet binary + run: cargo build --release --bin faucet --features="local-discovery,gifting" + timeout-minutes: 30 + + - name: Build testing executable + run: cargo test --release -p sn_node --features=local-discovery --test spend_simulation --no-run + env: + # only set the target dir for windows to bypass the linker issue. + # happens if we build the node manager via testnet action + CARGO_TARGET_DIR: ${{ matrix.os == 'windows-latest' && './test-target' || '.' }} + timeout-minutes: 30 + + - name: Start a local network + uses: maidsafe/sn-local-testnet-action@main + with: + action: start + interval: 2000 + node-count: 50 + node-path: target/release/safenode + faucet-path: target/release/faucet + platform: ${{ matrix.os }} + build: true + + - name: Check SAFE_PEERS was set + shell: bash + run: | + if [[ -z "$SAFE_PEERS" ]]; then + echo "The SAFE_PEERS variable has not been set" + exit 1 + else + echo "SAFE_PEERS has been set to $SAFE_PEERS" + fi + - name: execute the spend simulation run: cargo test --release -p sn_node --features="local-discovery" --test spend_simulation -- --nocapture --test-threads=1 env: @@ -417,7 +478,7 @@ jobs: uses: maidsafe/sn-local-testnet-action@main with: action: stop - log_file_prefix: safe_test_logs_spend + log_file_prefix: safe_test_logs_spend_simulation platform: ${{ matrix.os }} token_distribution_test: diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 37038ccf62..97d8298008 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -203,7 +203,7 @@ jobs: timeout-minutes: 30 - name: Build testing executable - run: cargo test --release -p sn_node --features=local-discovery --test sequential_transfers --test storage_payments --test double_spend --test spend_simulation --no-run + run: cargo test --release -p sn_node --features=local-discovery --test sequential_transfers --test storage_payments --test double_spend --no-run env: # only set the target dir for windows to bypass the linker issue. # happens if we build the node manager via testnet action @@ -221,7 +221,7 @@ jobs: build: true - name: execute the sequential transfers test - run: cargo test --release -p sn_node --features="local-discovery" --test sequential_transfers -- --nocapture + run: cargo test --release -p sn_node --features="local-discovery" --test sequential_transfers -- --nocapture --test-threads=1 env: CARGO_TARGET_DIR: ${{ matrix.os == 'windows-latest' && './test-target' || '.' }} SN_LOG: "all" @@ -240,6 +240,65 @@ jobs: CARGO_TARGET_DIR: ${{ matrix.os == 'windows-latest' && './test-target' || '.' }} timeout-minutes: 25 + - name: Small wait to allow reward receipt + run: sleep 30 + timeout-minutes: 1 + + - name: Stop the local network and upload logs + if: always() + uses: maidsafe/sn-local-testnet-action@main + with: + action: stop + log_file_prefix: safe_test_logs_spend + platform: ${{ matrix.os }} + + - name: post notification to slack on failure + if: ${{ failure() }} + uses: bryannice/gitactions-slack-notification@2.0.0 + env: + SLACK_INCOMING_WEBHOOK: ${{ secrets.SLACK_GH_ACTIONS_WEBHOOK_URL }} + SLACK_MESSAGE: "Please check the logs for the run at ${{ env.WORKFLOW_URL }}/${{ github.run_id }}" + SLACK_TITLE: "Nightly Spend Test Run Failed" + + # runs with increased node count + spend_simulation: + name: spend simulation + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + + - uses: Swatinem/rust-cache@v2 + continue-on-error: true + + - name: Build binaries + run: cargo build --release --features=local-discovery --bin safenode --bin faucet + timeout-minutes: 30 + + - name: Build testing executable + run: cargo test --release -p sn_node --features=local-discovery --test spend_simulation --no-run + env: + # only set the target dir for windows to bypass the linker issue. + # happens if we build the node manager via testnet action + CARGO_TARGET_DIR: ${{ matrix.os == 'windows-latest' && './test-target' || '.' }} + timeout-minutes: 30 + + - name: Start a local network + uses: maidsafe/sn-local-testnet-action@main + with: + action: start + interval: 2000 + node-count: 50 + node-path: target/release/safenode + faucet-path: target/release/faucet + platform: ${{ matrix.os }} + build: true + - name: execute the spend simulation test run: cargo test --release -p sn_node --features="local-discovery" --test spend_simulation -- --nocapture --test-threads=1 env: @@ -255,7 +314,7 @@ jobs: uses: maidsafe/sn-local-testnet-action@main with: action: stop - log_file_prefix: safe_test_logs_spend + log_file_prefix: safe_test_logs_spend_simulation platform: ${{ matrix.os }} - name: post notification to slack on failure diff --git a/sn_node/tests/spend_simulation.rs b/sn_node/tests/spend_simulation.rs index 099ecbb7c5..f87371f684 100644 --- a/sn_node/tests/spend_simulation.rs +++ b/sn_node/tests/spend_simulation.rs @@ -29,7 +29,7 @@ use std::{ use tokio::sync::mpsc; use tracing::*; -const MAX_WALLETS: usize = 50; +const MAX_WALLETS: usize = 30; const MAX_CYCLES: usize = 10; const AMOUNT_PER_RECIPIENT: NanoTokens = NanoTokens::from(1000); /// The chance for an attack to happen. 1 in X chance.