Skip to content

Commit

Permalink
chore(code/test): Speed compilation of integration tests by using a s…
Browse files Browse the repository at this point in the history
…ingle test executable per crate

See https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html for background information
  • Loading branch information
romac committed Jan 6, 2025
1 parent 7ba35aa commit 524c702
Show file tree
Hide file tree
Showing 33 changed files with 80 additions and 89 deletions.
12 changes: 0 additions & 12 deletions code/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ members = [
"crates/test/mbt",
"crates/test/mempool",
"crates/network/test",
"crates/core-driver/test-utils",

# Starknet
"crates/starknet/*",
Expand Down Expand Up @@ -87,7 +86,6 @@ malachitebft-test = { version = "0.0.1", package = "informalsy
malachitebft-test-mbt = { version = "0.0.1", package = "informalsystems-malachitebft-test-mbt", path = "crates/test/mbt" }
malachitebft-test-mempool = { version = "0.0.1", package = "informalsystems-malachitebft-test-mempool", path = "crates/test/mempool" }
malachitebft-discovery-test = { version = "0.0.1", package = "informalsystems-malachitebft-discovery-test", path = "crates/network/test" }
malachitebft-core-driver-test-utils = { version = "0.0.1", package = "informalsystems-malachitebft-core-driver-test-utils", path = "crates/core-driver/test-utils" }

# Starknet
malachitebft-starknet-host = { version = "0.0.1", package = "informalsystems-malachitebft-starknet-host", path = "crates/starknet/host" }
Expand Down
1 change: 0 additions & 1 deletion code/crates/core-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ thiserror = { workspace = true, default-features = false }

[dev-dependencies]
malachitebft-test = { workspace = true }
malachitebft-core-driver-test-utils = { workspace = true }
18 changes: 0 additions & 18 deletions code/crates/core-driver/test-utils/Cargo.toml

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use malachitebft_core_state_machine::state::State;
use malachitebft_core_types::{Round, Validity};

use malachitebft_core_driver_test_utils::*;
use malachitebft_test::utils::validators::make_validators;
use malachitebft_test::{Height, Proposal, TestContext, ValidatorSet, Value};

use informalsystems_malachitebft_core_driver::{Driver, Input, Output};

use crate::utils::*;

// The following tests are performed:
// - L49 with commits from current rounds, no locked value, no valid value:
// `driver_steps_decide_current_with_no_locked_no_valid()`
Expand Down
4 changes: 4 additions & 0 deletions code/crates/core-driver/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod basic;
pub mod extra;

mod utils;
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![allow(clippy::needless_update)]

use malachitebft_core_driver::{Input, Output};
use malachitebft_core_state_machine::state::{RoundValue, State, Step};
use malachitebft_core_types::{NilOrVal, Round, SignedProposal, SignedVote, Timeout, Validity};
use malachitebft_test::{Address, Height, Proposal, Signature, TestContext, Value, Vote};

use informalsystems_malachitebft_core_driver::{Input, Output};

pub fn new_round_input(round: Round, proposer: Address) -> Input<TestContext> {
Input::NewRound(Height::new(1), round, proposer)
}
Expand Down
3 changes: 3 additions & 0 deletions code/crates/starknet/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ use malachitebft_starknet_host::spawn::spawn_node_actor;
use malachitebft_starknet_host::types::MockContext;
use malachitebft_starknet_host::types::{Height, PrivateKey, Validator, ValidatorSet};

#[cfg(test)]
pub mod tests;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Expected {
Exactly(usize),
Expand Down
7 changes: 7 additions & 0 deletions code/crates/starknet/test/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod n3f0;
pub mod n3f0_consensus_mode;
pub mod n3f0_pubsub_protocol;
pub mod n3f1;
pub mod value_sync;
pub mod vote_sync;
pub mod wal;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use informalsystems_malachitebft_starknet_test::{init_logging, TestBuilder};
use crate::{init_logging, TestBuilder};

#[tokio::test]
pub async fn all_correct_nodes() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::time::Duration;

use informalsystems_malachitebft_starknet_test::{init_logging, TestBuilder, TestParams};
use malachitebft_config::ValuePayload;

use crate::{init_logging, TestBuilder, TestParams};

async fn run_test(params: TestParams) {
init_logging(module_path!());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::time::Duration;

use bytesize::ByteSize;
use informalsystems_malachitebft_starknet_test::{init_logging, TestBuilder, TestParams};
use malachitebft_config::{GossipSubConfig, PubSubProtocol};

use crate::{init_logging, TestBuilder, TestParams};

async fn run_test(params: TestParams) {
init_logging(module_path!());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use informalsystems_malachitebft_starknet_test::{init_logging, TestBuilder};
use crate::{init_logging, TestBuilder};

#[tokio::test]
pub async fn proposer_fails_to_start() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::time::Duration;

use informalsystems_malachitebft_starknet_test::{init_logging, TestBuilder, TestParams};
use malachitebft_config::ValuePayload;

use crate::{init_logging, TestBuilder, TestParams};

pub async fn crash_restart_from_start(params: TestParams) {
init_logging(module_path!());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::time::Duration;

use informalsystems_malachitebft_starknet_test::{init_logging, TestBuilder, TestParams};
use malachitebft_config::ValuePayload;

use crate::{init_logging, TestBuilder, TestParams};

// NOTE: These tests are very similar to the Sync tests, with the difference that
// all nodes have the same voting power and therefore get stuck when one of them dies.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use malachitebft_core_types::SignedVote;
use malachitebft_engine::util::events::Event;
use malachitebft_starknet_host::types::MockContext;

use informalsystems_malachitebft_starknet_test::{
init_logging, HandlerResult, TestBuilder, TestParams,
};
use crate::{init_logging, HandlerResult, TestBuilder, TestParams};

#[tokio::test]
async fn proposer_crashes_after_proposing_parts_only() {
Expand Down
3 changes: 3 additions & 0 deletions code/crates/test/mbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ pub mod deserializers;
pub mod types;
pub mod utils;
pub mod votekeeper;

#[cfg(test)]
pub mod tests;
2 changes: 2 additions & 0 deletions code/crates/test/mbt/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod consensus;
pub mod votekeeper;
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#[path = "consensus/runner.rs"]
pub mod runner;
#[path = "consensus/utils.rs"]
pub mod utils;

use glob::glob;
use rand::rngs::StdRng;
use rand::SeedableRng;

use informalsystems_malachitebft_test_mbt::consensus::State;
use informalsystems_malachitebft_test_mbt::utils::{generate_test_traces, quint_seed};
use crate::consensus::State;
use crate::utils::{generate_test_traces, quint_seed};

pub mod runner;
pub mod utils;

use runner::ConsensusRunner;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use malachitebft_core_state_machine::{state::State as RoundState, state_machine:
use malachitebft_core_types::{Context, NilOrVal, Round};
use malachitebft_test::{Address, Height, TestContext};

use informalsystems_malachitebft_test_mbt as test;
use test::consensus::{Input as ModelInput, Output as ModelOutput, State};
use test::types::Step;

use itf::Runner as ItfRunner;

use crate::utils::{
use crate::consensus::{Input as ModelInput, Output as ModelOutput, State};
use crate::types::Step;

use super::utils::{
value_from_model, value_from_string, value_id_from_model, value_id_from_string, OTHER_PROCESS,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use rand::rngs::StdRng;

use malachitebft_test::{Address, PrivateKey, Value, ValueId};

use informalsystems_malachitebft_test_mbt as test;
use test::consensus::State;
use test::types::{NonNilValue, Value as ModelValue};
use crate::consensus::State;
use crate::types::{NonNilValue, Value as ModelValue};

pub const OTHER_PROCESS: &str = "Other";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#[path = "votekeeper/runner.rs"]
pub mod runner;
#[path = "votekeeper/utils.rs"]
pub mod utils;

use glob::glob;
use informalsystems_malachitebft_test_mbt::utils::generate_test_traces;
use informalsystems_malachitebft_test_mbt::votekeeper::State;

use rand::rngs::StdRng;
use rand::SeedableRng;

use crate::utils::generate_test_traces;
use crate::votekeeper::State;

pub mod runner;
pub mod utils;

use runner::VoteKeeperRunner;

const RANDOM_SEED: u64 = 0x42;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ use malachitebft_core_votekeeper::keeper::{Output, VoteKeeper};
use malachitebft_core_votekeeper::ThresholdParams;
use malachitebft_test::{Address, Height, Signature, TestContext, Vote};

use informalsystems_malachitebft_test_mbt as test;
use test::types::{Value as ModelValue, VoteType};
use test::votekeeper::VoteKeeperOutput::*;
use test::votekeeper::{State, WeightedVote};

use itf::Runner as ItfRunner;
use rand::rngs::StdRng;

use crate::utils::build_address_map;
use crate::types::{Value as ModelValue, VoteType};
use crate::votekeeper::VoteKeeperOutput::*;
use crate::votekeeper::{State, WeightedVote};

use super::utils::{build_validator_set, check_votes, value_from_model};
use super::utils::{build_address_map, build_validator_set, check_votes, value_from_model};

#[derive(Debug)]
pub struct VoteKeeperRunner {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::collections::HashMap;

use rand::{CryptoRng, RngCore};

use informalsystems_malachitebft_test_mbt as test;
use malachitebft_core_types::NilOrVal;
use malachitebft_core_votekeeper as core;
use malachitebft_test::{
Address, PrivateKey, PublicKey, TestContext, Validator, ValidatorSet, ValueId,
};
use test::types::Value;

use crate::types::Value;

pub const VALIDATORS: [&str; 3] = ["alice", "bob", "john"];

Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn value_from_model(value: &Value) -> NilOrVal<ValueId> {
}

pub fn check_votes(
expected: &test::votekeeper::VoteCount,
expected: &crate::votekeeper::VoteCount,
actual: &core::count::VoteCount<TestContext>,
address_map: &HashMap<String, Address>,
) {
Expand Down
3 changes: 2 additions & 1 deletion code/crates/wal/benches/wal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use std::fs;
use std::path::PathBuf;

use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use tempfile::tempdir;

use informalsystems_malachitebft_wal::Log;
Expand Down
5 changes: 4 additions & 1 deletion code/crates/wal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

//! Write-Ahead Log (WAL) implementation
mod ext;
mod file;
mod storage;
mod version;
Expand All @@ -12,3 +11,7 @@ pub mod log;
pub use file::{Log, LogEntry, LogIter};
pub use storage::Storage;
pub use version::Version;

// For use in tests
#[doc(hidden)]
pub mod ext;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::sync::LazyLock;
use std::time::Duration;
use std::{fs, io, str};

use informalsystems_malachitebft_wal::{Log, Version};

use testdir::{NumberedDir, NumberedDirBuilder};

use informalsystems_malachitebft_wal::{Log, Version};

static TESTDIR: LazyLock<NumberedDir> =
LazyLock::new(|| NumberedDirBuilder::new("wal".to_string()).create().unwrap());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#![cfg(all(feature = "compression", not(feature = "force-compression")))]

use std::io;
use std::sync::LazyLock;

use informalsystems_malachitebft_wal::Log;
use testdir::{NumberedDir, NumberedDirBuilder};

use informalsystems_malachitebft_wal::Log;

static TESTDIR: LazyLock<NumberedDir> =
LazyLock::new(|| NumberedDirBuilder::new("wal".to_string()).create().unwrap());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ use std::fs::OpenOptions;
use std::io::{self, Seek, SeekFrom, Write};
use std::sync::LazyLock;

use informalsystems_malachitebft_wal::{Log, Version};
use testdir::{NumberedDir, NumberedDirBuilder};

#[allow(dead_code)]
#[path = "../src/ext.rs"]
mod ext;
use ext::*;
use informalsystems_malachitebft_wal::ext::*;
use informalsystems_malachitebft_wal::{Log, Version};

static TESTDIR: LazyLock<NumberedDir> =
LazyLock::new(|| NumberedDirBuilder::new("wal".to_string()).create().unwrap());
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions code/crates/wal/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod basic;
pub mod corruption;
pub mod crashes;
pub mod stress;

#[cfg(all(feature = "compression", not(feature = "force-compression")))]
pub mod compression;
Loading

0 comments on commit 524c702

Please sign in to comment.