Skip to content

Commit

Permalink
build: update workflow, pass irohad via env
Browse files Browse the repository at this point in the history
Signed-off-by: 0x009922 <[email protected]>
  • Loading branch information
0x009922 committed Sep 27, 2024
1 parent 8b29ff3 commit 70120b8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 56 deletions.
42 changes: 3 additions & 39 deletions .github/workflows/iroha2-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ jobs:
path: ${{ env.DOCKER_COMPOSE_PATH }}
- name: Run tests, with coverage
run: |
mold --run cargo test --all-features --no-fail-fast --workspace --exclude iroha
mold --run cargo test --all-features --no-fail-fast -p iroha -- --skip integration
cargo build --bin irohad
export IROHAD_EXEC=$(realpath ./target/debug/irohad)
mold --run cargo test --all-features --no-fail-fast --workspace
env:
RUSTFLAGS: "-C instrument-coverage"
LLVM_PROFILE_FILE: "iroha-%p-%m.profraw"
Expand All @@ -91,43 +92,6 @@ jobs:
name: lcov.info
path: lcov.info

# include: iroha/tests/integration/
# exclude: iroha/tests/integration/extra_functional
integration:
runs-on: [self-hosted, Linux, iroha2]
needs: build_executor
container:
image: hyperledger/iroha2-ci:nightly-2024-09-09
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Download executor.wasm file
uses: actions/download-artifact@v4
with:
name: executor.wasm
path: ${{ env.DOCKER_COMPOSE_PATH }}
- name: Run tests, with no-default-features
run: mold --run cargo test --no-default-features --no-fail-fast -p iroha integration -- --skip extra_functional

# include: iroha/tests/integration/extra_functional
extra_functional:
runs-on: [self-hosted, Linux, iroha2]
needs: build_executor
container:
image: hyperledger/iroha2-ci:nightly-2024-09-09
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Download executor.wasm file
uses: actions/download-artifact@v4
with:
name: executor.wasm
path: ${{ env.DOCKER_COMPOSE_PATH }}
- name: Run tests
run: mold --run cargo test --no-default-features --no-fail-fast -p iroha extra_functional -- --test-threads=1

# Run the job to check that the docker containers are properly buildable
pr-generator-build:
# Job will only execute if the head of the pull request is a branch for PR-generator case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn register_new_peer() -> Result<()> {
let client = network.client();
spawn_blocking(move || client.submit_blocking(register)).await??;

timeout(Duration::from_secs(2), peer.once_block_height(2)).await?;
timeout(Duration::from_secs(2), peer.once_block(2)).await?;

Ok(())
}
Expand All @@ -68,7 +68,7 @@ async fn connected_peers_with_f(faults: usize) -> Result<()> {
network.pipeline_time() * 10,
randomized_peers
.iter()
.map(|peer| peer.once_block_height(2))
.map(|peer| peer.once_block(2))
.collect::<FuturesUnordered<_>>()
.collect::<Vec<_>>(),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha/tests/integration/extra_functional/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn multiple_genesis_peers(n_peers: usize, n_genesis_peers: usize) -> eyre:
let genesis = (i < n_genesis_peers).then_some(network.genesis());
async move {
peer.start(cfg, genesis).await;
peer.once_block_height(1).await;
peer.once_block(1).await;
}
})
.collect::<FuturesUnordered<_>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn restarted_peer_should_have_the_same_asset_amount() -> Result<()> {
let peer = network.peer();
peer.start(network.config().clone(), Some(network.genesis()))
.await;
timeout(Duration::from_secs(1), peer.once_block_height(1)).await?;
timeout(Duration::from_secs(1), peer.once_block(1)).await?;

let client = peer.client();
let assets = spawn_blocking(move || {
Expand Down
51 changes: 38 additions & 13 deletions crates/iroha_test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ mod fslock_ports;
use core::{fmt::Debug, time::Duration};
use std::{
ops::Deref,
path::{Path, PathBuf},
process::{ExitStatus, Stdio},
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
Arc,
Arc, OnceLock,
},
};

Expand Down Expand Up @@ -48,13 +49,38 @@ use tokio::{
use toml::Table;

const INSTANT_PIPELINE_TIME: Duration = Duration::from_millis(10);
const DEFAULT_BLOCK_SYNC: Duration = Duration::from_millis(25);
const PEER_START_TIMEOUT: Duration = Duration::from_secs(5);
const DEFAULT_BLOCK_SYNC: Duration = Duration::from_millis(150);
const PEER_START_TIMEOUT: Duration = Duration::from_secs(30);
const PEER_KILL_TIMEOUT: Duration = Duration::from_secs(5);
const SYNC_TIMEOUT: Duration = Duration::from_secs(30);

// TODO: read from ENV?
const IROHA_BIN: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../target/release/irohad");
fn iroha_bin() -> impl AsRef<Path> {
const DEFAULT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../target/release/irohad");
const ENV: &str = "IROHAD_EXEC";

static PATH: OnceLock<PathBuf> = OnceLock::new();

PATH.get_or_init(|| {
let path = std::env::var(ENV)
.ok()
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from(DEFAULT));

if !std::fs::exists(&path).expect("should not fail") {
panic!(
" Cannot run `iroha_test_network` without `irohad` binary provided.\n \
Looked at path: {}\n \
Make sure you have pre-built `irohad` in `release` target\n \
or provide a custom path via `{}` environment variable",
path.display(),
ENV
);
}

eprintln!("Using `irohad`: {}", path.display());
path
})
}

/// Network of peers
pub struct Network {
Expand Down Expand Up @@ -103,7 +129,7 @@ impl Network {
(i == 0).then_some(&self.genesis),
)
.await;
peer.once_block_height(1).await;
peer.once_block(1).await;
})
.collect::<FuturesUnordered<_>>()
.collect::<Vec<_>>(),
Expand Down Expand Up @@ -175,7 +201,7 @@ impl Network {
self.peers
.iter()
.filter(|x| x.is_running())
.map(|x| x.once_block_height(height))
.map(|x| x.once_block(height))
.collect::<FuturesUnordered<_>>()
.collect::<Vec<_>>(),
)
Expand Down Expand Up @@ -391,7 +417,7 @@ pub enum PeerLifecycleEvent {
/// Process was killed
Killed,
/// Caught a related pipeline event
BlockCommitted { height: u64 },
BlockApplied { height: u64 },
}

/// Controls execution of `irohad` child process.
Expand Down Expand Up @@ -516,7 +542,7 @@ impl NetworkPeer {
.expect("tmp dir is available and genesis was not written before");
}

let mut cmd = tokio::process::Command::new(IROHA_BIN);
let mut cmd = tokio::process::Command::new(iroha_bin().as_ref());
cmd.stdout(Stdio::piped())
.stderr(Stdio::piped())
.kill_on_drop(true)
Expand Down Expand Up @@ -633,11 +659,10 @@ impl NetworkPeer {
match event {
EventBox::Pipeline(PipelineEventBox::Block(block)) => {
// FIXME: should we wait for `Applied` event instead?
if *block.status() == BlockStatus::Committed {
if *block.status() == BlockStatus::Applied {
let height = block.header().height().get();
eprintln!("{log_prefix} block committed: {height}",);
let _ =
events_tx.send(PeerLifecycleEvent::BlockCommitted { height });
let _ = events_tx.send(PeerLifecycleEvent::BlockApplied { height });
block_height_tx.send_modify(|x| *x = Some(height));
}
}
Expand Down Expand Up @@ -716,7 +741,7 @@ impl NetworkPeer {
/// Wait until peer's block height reaches N.
///
/// Resolves immediately if peer is already running _and_ its current block height is greater or equal to N.
pub async fn once_block_height(&self, n: u64) {
pub async fn once_block(&self, n: u64) {
let mut recv = self.block_height.subscribe();

if recv.borrow().map(|x| x >= n).unwrap_or(false) {
Expand Down

0 comments on commit 70120b8

Please sign in to comment.