Skip to content

Commit

Permalink
test(validator): enable multithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
drmick committed Apr 24, 2024
1 parent 4110af2 commit 79c5091
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
37 changes: 19 additions & 18 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ log = "0.4.21"

[dev-dependencies]
tempfile = { workspace = true }
tokio = { version = "1", features = ["rt-multi-thread"] }
tracing-test = { workspace = true }
tycho-core = { workspace = true, features = ["test"] }
tycho-storage = { workspace = true, features = ["test"] }
Expand Down
1 change: 0 additions & 1 deletion collator/src/validator/test_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ where
&mut self,
_session: Arc<ValidationSessionInfo>,
) -> Result<ValidatorTaskResult> {
//STUB: do nothing
Ok(ValidatorTaskResult::Void)
}

Expand Down
7 changes: 3 additions & 4 deletions collator/src/validator/validator_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,11 @@ where
Duration::from_millis(0)
} else {
let exponential_backoff = INITIAL_BACKOFF * BACKOFF_FACTOR.pow(iteration - 1);
let calculated_duration = exponential_backoff + NETWORK_TIMEOUT;

if calculated_duration > MAX_BACKOFF {
if exponential_backoff > MAX_BACKOFF {
MAX_BACKOFF
} else {
calculated_duration
exponential_backoff
}
};

Expand Down Expand Up @@ -522,7 +521,7 @@ where
trace!(target: tracing_targets::VALIDATOR, validator_pubkey=?validator.public_key.as_bytes(), "trying to send request for getting signatures from validator");

let response = tokio::time::timeout(
Duration::from_secs(1),
NETWORK_TIMEOUT,
cloned_private_overlay.query(
&cloned_network,
&PeerId(validator.public_key.to_bytes()),
Expand Down
4 changes: 3 additions & 1 deletion collator/tests/adapter_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tycho_block_util::state::{MinRefMcStateTracker, ShardStateStuff};
use tycho_collator::state_node::{
StateNodeAdapter, StateNodeAdapterStdImpl, StateNodeEventListener,
};
use tycho_collator::test_utils::prepare_test_storage;
use tycho_collator::types::BlockStuffForSync;
use tycho_core::block_strider::provider::BlockProvider;
use tycho_core::block_strider::subscriber::test::PrintSubscriber;
Expand Down Expand Up @@ -75,7 +76,7 @@ async fn test_add_and_get_block() {

#[tokio::test]
async fn test_storage_accessors() {
let (provider, storage) = prepare_state_apply().await.unwrap();
let (provider, storage) = prepare_test_storage().await.unwrap();

let block_strider = BlockStrider::builder()
.with_provider(provider)
Expand All @@ -84,6 +85,7 @@ async fn test_storage_accessors() {
.build_with_state_applier(MinRefMcStateTracker::default(), storage.clone());

block_strider.run().await.unwrap();

let counter = Arc::new(AtomicUsize::new(0));
let listener = Arc::new(MockEventListener {
accepted_count: counter.clone(),
Expand Down
8 changes: 4 additions & 4 deletions collator/tests/validator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ async fn test_validator_accept_block_by_state() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
async fn test_validator_accept_block_by_network() -> anyhow::Result<()> {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn test_validator_accept_block_by_network() -> Result<()> {
try_init_test_tracing(tracing_subscriber::filter::LevelFilter::DEBUG);
tycho_util::test::init_logger("test_validator_accept_block_by_network");

let network_nodes = make_network(2);
let blocks_amount = 100;
let network_nodes = make_network(20);
let blocks_amount = 10;
let sessions = 2;

let mut validators = vec![];
Expand Down

0 comments on commit 79c5091

Please sign in to comment.