Skip to content

Commit 7914bb9

Browse files
apollo_integration_tests: remove IndexMap and BTreeSet from NodeSetup reopened (#10418)
1 parent 195e583 commit 7914bb9

File tree

1 file changed

+66
-49
lines changed

1 file changed

+66
-49
lines changed

crates/apollo_integration_tests/src/integration_test_manager.rs

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::collections::{BTreeSet, HashMap, HashSet};
1+
use std::collections::{HashMap, HashSet};
22
use std::future::Future;
33
use std::net::{Ipv4Addr, SocketAddr};
44
use std::panic;
5-
use std::path::PathBuf;
65
use std::time::Duration;
76

87
use apollo_base_layer_tests::anvil_base_layer::AnvilBaseLayer;
98
use apollo_deployments::deployment_definitions::ComponentConfigInService;
9+
use apollo_deployments::service::{NodeService, NodeType};
1010
use apollo_http_server::test_utils::HttpTestClient;
1111
use apollo_http_server_config::config::HttpServerConfig;
1212
use apollo_infra_utils::dumping::serialize_to_file;
@@ -27,7 +27,6 @@ use blockifier::bouncer::BouncerWeights;
2727
use blockifier::context::ChainInfo;
2828
use futures::future::join_all;
2929
use futures::TryFutureExt;
30-
use indexmap::IndexMap;
3130
use mempool_test_utils::starknet_api_test_utils::{
3231
contract_class,
3332
AccountId,
@@ -95,7 +94,8 @@ fn block_max_capacity_gas() -> GasAmount {
9594
}
9695

9796
pub struct NodeSetup {
98-
executables: IndexMap<BTreeSet<ComponentConfigInService>, ExecutableSetup>,
97+
node_type: NodeType,
98+
executables: HashMap<NodeService, ExecutableSetup>,
9999

100100
// Client for adding transactions to the sequencer node.
101101
pub add_tx_http_client: HttpTestClient,
@@ -108,35 +108,44 @@ pub struct NodeSetup {
108108
}
109109

110110
fn get_executable_by_component(
111-
executables: &IndexMap<BTreeSet<ComponentConfigInService>, ExecutableSetup>,
111+
node_type: NodeType,
112+
executables: &HashMap<NodeService, ExecutableSetup>,
112113
component: ComponentConfigInService,
113114
) -> &ExecutableSetup {
114115
executables
115-
.iter()
116-
.find(|(components, _)| components.contains(&component))
117-
.map(|(_, executable)| executable)
118-
.unwrap_or_else(|| {
119-
panic!("Expected at least one executable with component {:?}", component)
120-
})
116+
.get(
117+
&node_type
118+
.get_services_of_components(component.clone())
119+
.into_iter()
120+
.next()
121+
.unwrap_or_else(|| {
122+
panic!("Expected at least one executable with component {:?}", component)
123+
}),
124+
)
125+
.unwrap()
121126
}
122127

123128
impl NodeSetup {
124129
pub fn new(
125-
executables: IndexMap<BTreeSet<ComponentConfigInService>, ExecutableSetup>,
130+
node_type: NodeType,
131+
executables: HashMap<NodeService, ExecutableSetup>,
126132
storage_handles: StorageTestHandles,
127133
) -> Self {
128-
let http_server_config =
129-
get_executable_by_component(&executables, ComponentConfigInService::HttpServer)
130-
.base_app_config
131-
.get_config()
132-
.http_server_config
133-
.as_ref()
134-
.unwrap_or_else(|| panic!("Http server config should be set for this node"));
134+
let http_server_config = get_executable_by_component(
135+
node_type,
136+
&executables,
137+
ComponentConfigInService::HttpServer,
138+
)
139+
.base_app_config
140+
.get_config()
141+
.http_server_config
142+
.as_ref()
143+
.unwrap_or_else(|| panic!("Http server config should be set for this node"));
135144

136145
let HttpServerConfig { ip, port } = http_server_config;
137146
let add_tx_http_client = HttpTestClient::new(SocketAddr::new(*ip, *port));
138147

139-
Self { executables, add_tx_http_client, storage_handles }
148+
Self { node_type, executables, add_tx_http_client, storage_handles }
140149
}
141150

142151
async fn send_rpc_tx_fn(&self, rpc_tx: RpcTransaction) -> TransactionHash {
@@ -163,19 +172,6 @@ impl NodeSetup {
163172
self.executables.values_mut()
164173
}
165174

166-
pub fn set_executable_config_path(
167-
&mut self,
168-
index: usize,
169-
new_path: PathBuf,
170-
) -> Result<(), &'static str> {
171-
if let Some(exec) = self.executables.get_index_mut(index) {
172-
exec.1.node_config_path = new_path;
173-
Ok(())
174-
} else {
175-
panic!("Invalid executable index")
176-
}
177-
}
178-
179175
pub fn generate_simulator_ports_json(&self, path: &str) {
180176
let json_data = serde_json::json!({
181177
HTTP_PORT_ARG: self.get_http_server().get_config().http_server_config.as_ref().expect("Should have http server config").port,
@@ -185,19 +181,35 @@ impl NodeSetup {
185181
}
186182

187183
pub fn get_batcher(&self) -> &ExecutableSetup {
188-
get_executable_by_component(&self.executables, ComponentConfigInService::Batcher)
184+
get_executable_by_component(
185+
self.node_type,
186+
&self.executables,
187+
ComponentConfigInService::Batcher,
188+
)
189189
}
190190

191191
pub fn get_http_server(&self) -> &ExecutableSetup {
192-
get_executable_by_component(&self.executables, ComponentConfigInService::HttpServer)
192+
get_executable_by_component(
193+
self.node_type,
194+
&self.executables,
195+
ComponentConfigInService::HttpServer,
196+
)
193197
}
194198

195199
pub fn get_state_sync(&self) -> &ExecutableSetup {
196-
get_executable_by_component(&self.executables, ComponentConfigInService::StateSync)
200+
get_executable_by_component(
201+
self.node_type,
202+
&self.executables,
203+
ComponentConfigInService::StateSync,
204+
)
197205
}
198206

199207
pub fn get_consensus_manager(&self) -> &ExecutableSetup {
200-
get_executable_by_component(&self.executables, ComponentConfigInService::Consensus)
208+
get_executable_by_component(
209+
self.node_type,
210+
&self.executables,
211+
ComponentConfigInService::Consensus,
212+
)
201213
}
202214

203215
pub fn run(self) -> RunningNode {
@@ -828,15 +840,20 @@ async fn get_sequencer_setup_configs(
828840
num_of_consolidated_nodes + num_of_distributed_nodes + num_of_hybrid_nodes,
829841
);
830842
for _ in 0..num_of_consolidated_nodes {
831-
node_component_configs.push(create_consolidated_component_configs());
843+
node_component_configs
844+
.push((create_consolidated_component_configs(), NodeType::Consolidated));
832845
}
833846
for _ in 0..num_of_hybrid_nodes {
834-
node_component_configs
835-
.push(create_hybrid_component_configs(&mut available_ports_generator));
847+
node_component_configs.push((
848+
create_hybrid_component_configs(&mut available_ports_generator),
849+
NodeType::Hybrid,
850+
));
836851
}
837852
for _ in 0..num_of_distributed_nodes {
838-
node_component_configs
839-
.push(create_distributed_component_configs(&mut available_ports_generator));
853+
node_component_configs.push((
854+
create_distributed_component_configs(&mut available_ports_generator),
855+
NodeType::Distributed,
856+
));
840857
}
841858

842859
info!("Creating node configurations.");
@@ -900,8 +917,10 @@ async fn get_sequencer_setup_configs(
900917
.expect("Failed to get an AvailablePorts instance for node configs");
901918

902919
// Create nodes.
903-
for (node_index, node_component_config) in node_component_configs.into_iter().enumerate() {
904-
let mut executables = IndexMap::new();
920+
for (node_index, (node_component_config, node_type)) in
921+
node_component_configs.into_iter().enumerate()
922+
{
923+
let mut executables = HashMap::new();
905924

906925
let mut consensus_manager_config = consensus_manager_configs.remove(0);
907926
let mempool_p2p_config = mempool_p2p_configs.remove(0);
@@ -924,9 +943,7 @@ async fn get_sequencer_setup_configs(
924943
);
925944

926945
// Per node, create the executables constituting it.
927-
for (component_set, executable_component_config) in node_component_config.into_iter() {
928-
let component_set = component_set.get_components_in_service();
929-
946+
for (node_service, executable_component_config) in node_component_config.into_iter() {
930947
// Set a monitoring endpoint for each executable.
931948
let monitoring_endpoint_config = MonitoringEndpointConfig {
932949
port: config_available_ports.get_next_port(),
@@ -958,12 +975,12 @@ async fn get_sequencer_setup_configs(
958975
custom_paths.as_ref().and_then(|paths| paths.get_config_path(&node_execution_id));
959976

960977
executables.insert(
961-
component_set,
978+
node_service,
962979
ExecutableSetup::new(base_app_config, node_execution_id, exec_config_path).await,
963980
);
964981
}
965982

966-
nodes.push(NodeSetup::new(executables, storage_setup.storage_handles));
983+
nodes.push(NodeSetup::new(node_type, executables, storage_setup.storage_handles));
967984
}
968985

969986
(nodes, node_indices)

0 commit comments

Comments
 (0)