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

Testing multiple zebrads #80

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
94 changes: 94 additions & 0 deletions testutils/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;
use zcash_protocol::{PoolType, ShieldedProtocol};

use testvectors::REG_O_ADDR_FROM_ABANDONART;
use tokio::task::{AbortHandle, JoinSet};
use zingolib::testutils::lightclient::{from_inputs, get_base_address};

use zingo_infra_testutils::client;
Expand Down Expand Up @@ -79,6 +80,99 @@ async fn launch_zebrad_with_cache() {
assert_eq!(zebrad.get_chain_height().await, 52.into());
}

#[ignore = "added to test multiple zebrad instances"]
#[tokio::test]
async fn launch_zebrad_with_cache_again() {
tracing_subscriber::fmt().init();

let zebrad = Zebrad::launch(ZebradConfig {
zebrad_bin: ZEBRAD_BIN,
network_listen_port: None,
rpc_listen_port: None,
activation_heights: network::ActivationHeights::default(),
miner_address: ZEBRAD_DEFAULT_MINER,
chain_cache: Some(utils::chain_cache_dir().join("client_rpc_tests_large")),
network: network::Network::Regtest,
})
.await
.unwrap();
zebrad.print_stdout();
zebrad.print_stderr();

assert_eq!(zebrad.get_chain_height().await, 52.into());
}

#[ignore = "added to test multiple zebrad instances"]
#[tokio::test]
async fn launch_zebrad_multiple_times_with_cache() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a sequential launch of zebrad's. Notice how there are being awaited.

We need a single test to launch 2+ instances in parallel. In as comparable as possible of a way as how nextest run launches 2 tests and each test launches a zebrad process.

Only then will they be really competing for the cache dir lock.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. Are you saying that...

tracing_subscriber::fmt().init();

let zebrad1 = Zebrad::launch(ZebradConfig {
Copy link
Contributor Author

@ala-mode ala-mode Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This zebrad1 being launched ...

zebrad_bin: ZEBRAD_BIN,
network_listen_port: None,
rpc_listen_port: None,
activation_heights: network::ActivationHeights::default(),
miner_address: ZEBRAD_DEFAULT_MINER,
chain_cache: Some(utils::chain_cache_dir().join("client_rpc_tests_large")),
network: network::Network::Regtest,
})
.await
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awaited here...

.unwrap();
zebrad1.print_stdout();
zebrad1.print_stderr();

let zebrad2 = Zebrad::launch(ZebradConfig {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stops because this zebrad2 launching with the same chain_cache config..

zebrad_bin: ZEBRAD_BIN,
network_listen_port: None,
rpc_listen_port: None,
activation_heights: network::ActivationHeights::default(),
miner_address: ZEBRAD_DEFAULT_MINER,
chain_cache: Some(utils::chain_cache_dir().join("client_rpc_tests_large")),
network: network::Network::Regtest,
})
.await
.unwrap();
zebrad2.print_stdout();
zebrad2.print_stderr();

// Don't stop either zebrad
assert_eq!(zebrad1.get_chain_height().await, 52.into());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and means this test running zebrad1 ..

assert_eq!(zebrad2.get_chain_height().await, 52.into());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or this one, is corrupted because the launches are being awaited?

I get the error ..IO error: While lock file... with launch_zebrad_multiple_times_with_cache and either
launch_zebrad_with_cache or launch_zebrad_with_cache_again

though I have not completely isolated the chain_cache dir yet, I think your fix will make all of these pass.

We can also write a test that will spawn multiple tasks, but I think these tests are useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

launch_zebrad_multiple_times_with_cache is failing because zebrad1 isn't being closed. If you do close it, it should launch both alright.

The key aspect is that they only raco for the lock if they are both running at the same time.

launch_zebrad_multiple_times_with_cache runs them sequentially, since its awaiting them.

I agree that it's an useful test. Could be made into 2 distinct ones:

  • one that does just this and DOESNT stop zebrad1 and it asserts that it fails (without the copy cache fix)
  • one that does stop zebrad1 and asserts that both run alright.

BUT this test isn't yet running 2 zebrad instances in parallel like 2 distinct tests each spawning a separate zebrad processes would. That's what we are aiming for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, in this test, against current dev, it is running two instances at the same time, with the same cache... please read my comment below.

}

#[ignore = "added to test multiple zebrad instances"]
#[tokio::test]
async fn launch_zebrad_multiple_times_in_tokio_tasks_with_cache() {
tracing_subscriber::fmt().init();

let mut tests_set: JoinSet<()> = JoinSet::new();
// spawn 3 tests as tasks
for _ in 0..=2 {
tests_set.spawn(async {
let zebrad = Zebrad::launch(ZebradConfig {
zebrad_bin: ZEBRAD_BIN,
network_listen_port: None,
rpc_listen_port: None,
activation_heights: network::ActivationHeights::default(),
miner_address: ZEBRAD_DEFAULT_MINER,
chain_cache: Some(utils::chain_cache_dir().join("client_rpc_tests_large")),
network: network::Network::Regtest,
})
.await
.expect("future inside task to unwrap");
zebrad.print_stdout();
zebrad.print_stderr();
// assert within task
assert_eq!(zebrad.get_chain_height().await, 52.into());
});

// Don't stop either zebrad
}
// will only be joined when all tasks have completed launch and asserted a chain height.
tests_set.join_all().await;
// returns pass
}

#[tokio::test]
async fn launch_localnet_zainod_zcashd() {
tracing_subscriber::fmt().init();
Expand Down