Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup and stabilize unit and integration tests #1231

Merged
merged 6 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

27 changes: 9 additions & 18 deletions crates/fuel-core/src/p2p_test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{
use fuel_core_p2p::{
codecs::postcard::PostcardCodec,
network_service::FuelP2PService,
PeerId,
};
use fuel_core_poa::{
ports::BlockImporter,
Expand Down Expand Up @@ -110,27 +109,15 @@ pub struct Nodes {
/// Nodes accessible by their name.
pub struct NamedNodes(pub HashMap<String, Node>);

fn map_listener_address(bootstrap_id: &PeerId, addr: &Multiaddr) -> Multiaddr {
format!("{addr}/p2p/{bootstrap_id}").parse().unwrap()
}

impl Bootstrap {
/// Spawn a bootstrap node.
pub async fn new(node_config: &Config) -> Self {
let bootstrap_config = extract_p2p_config(node_config);
let codec = PostcardCodec::new(bootstrap_config.max_block_size);
let mut bootstrap = FuelP2PService::new(bootstrap_config, codec);
bootstrap.start().unwrap();
bootstrap.start().await.unwrap();

// Wait for listener addresses.
while bootstrap.listeners().next().is_none() {
bootstrap.next_event().await;
}

let listeners: Vec<_> = bootstrap
.listeners()
.map(|addr| map_listener_address(&bootstrap.local_peer_id, addr))
.collect();
let listeners = bootstrap.multiaddrs();
let (kill, mut shutdown) = broadcast::channel(1);
tokio::spawn(async move {
loop {
Expand Down Expand Up @@ -325,9 +312,13 @@ pub fn make_config(name: String, chain_config: ChainConfig) -> Config {

pub async fn make_node(node_config: Config, test_txs: Vec<Transaction>) -> Node {
let db = Database::in_memory();
let node = FuelService::from_database(db.clone(), node_config)
.await
.unwrap();
let node = tokio::time::timeout(
Duration::from_secs(1),
FuelService::from_database(db.clone(), node_config),
)
.await
.expect("All services should start in less than 1 second")
.expect("The `FuelService should start without error");

let config = node.shared.config.clone();
Node {
Expand Down
7 changes: 5 additions & 2 deletions crates/services/consensus_module/poa/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,15 @@ where
I: BlockImporter<Database = D>,
{
async fn run(&mut self, watcher: &mut StateWatcher) -> anyhow::Result<bool> {
let should_continue;
// make sure we're synced first
while *self.sync_task_handle.shared.borrow() == SyncState::NotSynced {
tokio::select! {
biased;
_ = watcher.while_started() => {}
result = watcher.while_started() => {
should_continue = result?.started();
return Ok(should_continue);
}
_ = self.sync_task_handle.shared.changed() => {
if let SyncState::Synced(block_header) = &*self.sync_task_handle.shared.borrow() {
let (last_height, last_timestamp, last_block_created) =
Expand All @@ -513,7 +517,6 @@ where
}
}

let should_continue;
tokio::select! {
biased;
_ = watcher.while_started() => {
Expand Down
1 change: 1 addition & 0 deletions crates/services/p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ tracing = { workspace = true }

[dev-dependencies]
ctor = "0.1"
fuel-core-p2p = { path = ".", features = ["test-helpers"] }
fuel-core-trace = { path = "../../trace" }
fuel-core-types = { path = "../../types", features = [
"serde",
Expand Down
Loading