-
Notifications
You must be signed in to change notification settings - Fork 684
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[testloop] Refactor builder to separate node state and shared state (#…
…13041) The big function `setup_client` in builder now does not take builder as a parameter. We have extracted out the common state from builder into `SharedState` while we build `NodeState` for each individual client. This is useful as now if we have the node_state and shared_state, we can independently initialize nodes. This is useful for implementing node restarts and adding new nodes to test environment outside builder. Couple of other refactoring changes included. Before ``` fn setup_client( &mut self, idx: usize, tempdir: &TempDir, is_archival: bool, network_shared_state: &TestLoopNetworkSharedState, ) -> TestData {} ``` After ``` fn setup_client( identifier: &str, test_loop: &mut TestLoopV2, node_handle: NodeState, shared_state: &SharedState, ) -> TestData {} ```
- Loading branch information
1 parent
9dc2234
commit 01373eb
Showing
38 changed files
with
772 additions
and
626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#![cfg(test)] | ||
mod builder; | ||
mod env; | ||
mod setup; | ||
mod tests; | ||
mod utils; |
656 changes: 348 additions & 308 deletions
656
test-loop-tests/src/builder.rs → test-loop-tests/src/setup/builder.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod builder; | ||
pub mod env; | ||
pub mod state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
use std::sync::atomic::AtomicBool; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
use near_async::messaging::{IntoMultiSender, IntoSender, Sender}; | ||
use near_async::test_loop::data::TestLoopDataHandle; | ||
use near_async::test_loop::sender::TestLoopSender; | ||
use near_async::time::Duration; | ||
use near_chain_configs::{ClientConfig, Genesis}; | ||
use near_chunks::shards_manager_actor::ShardsManagerActor; | ||
use near_client::client_actor::ClientActorInner; | ||
use near_client::{PartialWitnessActor, ViewClientActorInner}; | ||
use near_jsonrpc::ViewClientSenderForRpc; | ||
use near_network::shards_manager::ShardsManagerRequestFromNetwork; | ||
use near_network::state_witness::PartialWitnessSenderForNetwork; | ||
use near_network::test_loop::{ | ||
ClientSenderForTestLoopNetwork, TestLoopNetworkSharedState, TestLoopPeerManagerActor, | ||
ViewClientSenderForTestLoopNetwork, | ||
}; | ||
use near_parameters::RuntimeConfigStore; | ||
use near_primitives::epoch_manager::EpochConfigStore; | ||
use near_primitives::network::PeerId; | ||
use near_primitives::types::AccountId; | ||
use near_primitives::upgrade_schedule::ProtocolUpgradeVotingSchedule; | ||
use near_store::Store; | ||
use nearcore::state_sync::StateSyncDumper; | ||
use tempfile::TempDir; | ||
|
||
use super::builder::DropConditionKind; | ||
use super::env::TestLoopChunksStorage; | ||
|
||
const NETWORK_DELAY: Duration = Duration::milliseconds(10); | ||
|
||
/// This is the state associate with the test loop environment. | ||
/// This state is shared across all nodes and none of it belongs to a specific node. | ||
pub struct SharedState { | ||
pub genesis: Genesis, | ||
/// Directory of the current test. This is automatically deleted once tempdir goes out of scope. | ||
pub tempdir: TempDir, | ||
pub epoch_config_store: EpochConfigStore, | ||
pub runtime_config_store: Option<RuntimeConfigStore>, | ||
/// Shared state across all the network actors. It handles the mapping between AccountId, | ||
/// PeerId, and the route back CryptoHash, so that individual network actors can do routing. | ||
pub network_shared_state: TestLoopNetworkSharedState, | ||
pub upgrade_schedule: ProtocolUpgradeVotingSchedule, | ||
/// Stores all chunks ever observed on chain. Used by drop conditions to simulate network drops. | ||
pub chunks_storage: Arc<Mutex<TestLoopChunksStorage>>, | ||
/// List of drop conditions that apply to all nodes in the network. | ||
pub drop_condition_kinds: Vec<DropConditionKind>, | ||
pub load_memtries_for_tracked_shards: bool, | ||
/// Flag to indicate if warmup is pending. This is used to ensure that warmup is only done once. | ||
pub warmup_pending: Arc<AtomicBool>, | ||
} | ||
|
||
/// This is the state associated with each node in the test loop environment before being built. | ||
/// The setup_client function will be called for each node to build the node and return TestData | ||
pub struct NodeState { | ||
pub account_id: AccountId, | ||
pub client_config: ClientConfig, | ||
pub store: Store, | ||
pub split_store: Option<Store>, | ||
} | ||
|
||
/// This is the state associated with each node in the test loop environment after being built. | ||
/// This state is specific to each node and is not shared across nodes. | ||
/// We can access each of the individual actors and senders from this state. | ||
#[derive(Clone)] | ||
pub struct TestData { | ||
pub account_id: AccountId, | ||
pub peer_id: PeerId, | ||
pub client_sender: TestLoopSender<ClientActorInner>, | ||
pub view_client_sender: TestLoopSender<ViewClientActorInner>, | ||
pub shards_manager_sender: TestLoopSender<ShardsManagerActor>, | ||
pub partial_witness_sender: TestLoopSender<PartialWitnessActor>, | ||
pub peer_manager_sender: TestLoopSender<TestLoopPeerManagerActor>, | ||
pub state_sync_dumper_handle: TestLoopDataHandle<StateSyncDumper>, | ||
} | ||
|
||
impl From<&TestData> for AccountId { | ||
fn from(data: &TestData) -> AccountId { | ||
data.account_id.clone() | ||
} | ||
} | ||
|
||
impl From<&TestData> for PeerId { | ||
fn from(data: &TestData) -> PeerId { | ||
data.peer_id.clone() | ||
} | ||
} | ||
|
||
impl From<&TestData> for ClientSenderForTestLoopNetwork { | ||
fn from(data: &TestData) -> ClientSenderForTestLoopNetwork { | ||
data.client_sender.clone().with_delay(NETWORK_DELAY).into_multi_sender() | ||
} | ||
} | ||
|
||
impl From<&TestData> for ViewClientSenderForRpc { | ||
fn from(data: &TestData) -> ViewClientSenderForRpc { | ||
data.view_client_sender.clone().with_delay(NETWORK_DELAY).into_multi_sender() | ||
} | ||
} | ||
|
||
impl From<&TestData> for ViewClientSenderForTestLoopNetwork { | ||
fn from(data: &TestData) -> ViewClientSenderForTestLoopNetwork { | ||
data.view_client_sender.clone().with_delay(NETWORK_DELAY).into_multi_sender() | ||
} | ||
} | ||
|
||
impl From<&TestData> for PartialWitnessSenderForNetwork { | ||
fn from(data: &TestData) -> PartialWitnessSenderForNetwork { | ||
data.partial_witness_sender.clone().with_delay(NETWORK_DELAY).into_multi_sender() | ||
} | ||
} | ||
|
||
impl From<&TestData> for Sender<ShardsManagerRequestFromNetwork> { | ||
fn from(data: &TestData) -> Sender<ShardsManagerRequestFromNetwork> { | ||
data.shards_manager_sender.clone().with_delay(NETWORK_DELAY).into_sender() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.