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

Simultaenously build Docker images used in tests #458

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions processor/src/tests/literal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mod bitcoin {
check::<IsTrue<{ Bitcoin::DUST >= bitcoin_serai::wallet::DUST }>>();
}

fn spawn_bitcoin() -> DockerTest {
serai_docker_tests::build("bitcoin".to_string());
async fn spawn_bitcoin() -> DockerTest {
serai_docker_tests::build("bitcoin".to_string()).await;

let composition = TestBodySpecification::with_image(
Image::with_repository("serai-dev-bitcoin").pull_policy(PullPolicy::Never),
Expand Down Expand Up @@ -73,8 +73,8 @@ mod monero {
use super::*;
use crate::networks::{Network, Monero};

fn spawn_monero() -> DockerTest {
serai_docker_tests::build("monero".to_string());
async fn spawn_monero() -> DockerTest {
serai_docker_tests::build("monero".to_string()).await;

let composition = TestBodySpecification::with_image(
Image::with_repository("serai-dev-monero").pull_policy(PullPolicy::Never),
Expand Down
70 changes: 40 additions & 30 deletions processor/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,59 @@ macro_rules! test_network {
test_key_gen::<$N>().await;
}

#[test]
fn $scanner() {
#[tokio::test]
async fn $scanner() {
*INIT_LOGGER;
let docker = $docker();
docker.run(|ops| async move {
test_scanner($network(&ops).await).await;
});
let docker = $docker().await;
docker
.run_async(|ops| async move {
test_scanner($network(&ops).await).await;
})
.await;
}

#[test]
fn $signer() {
#[tokio::test]
async fn $signer() {
*INIT_LOGGER;
let docker = $docker();
docker.run(|ops| async move {
test_signer($network(&ops).await).await;
});
let docker = $docker().await;
docker
.run_async(|ops| async move {
test_signer($network(&ops).await).await;
})
.await;
}

#[test]
fn $wallet() {
#[tokio::test]
async fn $wallet() {
*INIT_LOGGER;
let docker = $docker();
docker.run(|ops| async move {
test_wallet($network(&ops).await).await;
});
let docker = $docker().await;
docker
.run_async(|ops| async move {
test_wallet($network(&ops).await).await;
})
.await;
}

#[test]
fn $addresses() {
#[tokio::test]
async fn $addresses() {
*INIT_LOGGER;
let docker = $docker();
docker.run(|ops| async move {
test_addresses($network(&ops).await).await;
});
let docker = $docker().await;
docker
.run_async(|ops| async move {
test_addresses($network(&ops).await).await;
})
.await;
}

#[test]
fn $no_deadlock_in_multisig_completed() {
#[tokio::test]
async fn $no_deadlock_in_multisig_completed() {
*INIT_LOGGER;
let docker = $docker();
docker.run(|ops| async move {
test_no_deadlock_in_multisig_completed($network(&ops).await).await;
});
let docker = $docker().await;
docker
.run_async(|ops| async move {
test_no_deadlock_in_multisig_completed($network(&ops).await).await;
})
.await;
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ macro_rules! serai_test {
TestBodySpecification, DockerTest,
};

serai_docker_tests::build("serai".to_string());
serai_docker_tests::build("serai".to_string()).await;

let handle = concat!("serai_client-serai_node-", stringify!($name));

Expand Down
35 changes: 25 additions & 10 deletions tests/coordinator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ mod tests;

static UNIQUE_ID: OnceLock<Mutex<u16>> = OnceLock::new();

pub fn coordinator_instance(
pub fn coordinator_docker_name() -> String {
"serai-dev-coordinator".to_string()
}

pub async fn coordinator_instance(
name: &str,
message_queue_key: <Ristretto as Ciphersuite>::F,
) -> TestBodySpecification {
serai_docker_tests::build("coordinator".to_string());
serai_docker_tests::build("coordinator".to_string()).await;

TestBodySpecification::with_image(
Image::with_repository("serai-dev-coordinator").pull_policy(PullPolicy::Never),
Image::with_repository(coordinator_docker_name()).pull_policy(PullPolicy::Never),
)
.replace_env(
[
Expand All @@ -63,11 +67,15 @@ pub fn coordinator_instance(
)
}

pub fn serai_composition(name: &str) -> TestBodySpecification {
serai_docker_tests::build("serai".to_string());
pub fn serai_docker_name() -> String {
"serai-dev-serai".to_string()
}

pub async fn serai_composition(name: &str) -> TestBodySpecification {
serai_docker_tests::build("serai".to_string()).await;

TestBodySpecification::with_image(
Image::with_repository("serai-dev-serai").pull_policy(PullPolicy::Never),
Image::with_repository(serai_docker_name()).pull_policy(PullPolicy::Never),
)
.replace_cmd(vec![
"serai-node".to_string(),
Expand All @@ -82,15 +90,22 @@ pub fn serai_composition(name: &str) -> TestBodySpecification {
}

pub type Handles = (String, String, String);
pub fn coordinator_stack(
pub async fn coordinator_stack(
name: &str,
) -> (Handles, <Ristretto as Ciphersuite>::F, Vec<TestBodySpecification>) {
let serai_composition = serai_composition(name);
serai_docker_tests::build_batch(vec![
serai_docker_name(),
serai_message_queue_tests::docker_name(),
coordinator_docker_name(),
])
.await;

let serai_composition = serai_composition(name).await;

let (coord_key, message_queue_keys, message_queue_composition) =
serai_message_queue_tests::instance();
serai_message_queue_tests::instance().await;

let coordinator_composition = coordinator_instance(name, coord_key);
let coordinator_composition = coordinator_instance(name, coord_key).await;

// Give every item in this stack a unique ID
// Uses a Mutex as we can't generate a 8-byte random ID without hitting hostname length limits
Expand Down
2 changes: 1 addition & 1 deletion tests/coordinator/src/tests/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub async fn batch(
#[tokio::test]
async fn batch_test() {
let _one_at_a_time = ONE_AT_A_TIME.get_or_init(|| Mutex::new(())).lock();
let (processors, test) = new_test();
let (processors, test) = new_test().await;

test
.run_async(|ops| async move {
Expand Down
2 changes: 1 addition & 1 deletion tests/coordinator/src/tests/key_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub async fn key_gen<C: Ciphersuite>(
#[tokio::test]
async fn key_gen_test() {
let _one_at_a_time = ONE_AT_A_TIME.get_or_init(|| Mutex::new(())).lock();
let (processors, test) = new_test();
let (processors, test) = new_test().await;

test
.run_async(|ops| async move {
Expand Down
5 changes: 3 additions & 2 deletions tests/coordinator/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) const THRESHOLD: usize = ((COORDINATORS * 2) / 3) + 1;

pub(crate) static ONE_AT_A_TIME: OnceLock<Mutex<()>> = OnceLock::new();

pub(crate) fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, DockerTest) {
pub(crate) async fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, DockerTest) {
let mut coordinators = vec![];
let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
for i in 0 .. COORDINATORS {
Expand All @@ -33,7 +33,8 @@ pub(crate) fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, Dock
4 => "Eve",
5 => "Ferdie",
_ => panic!("needed a 7th name for a serai node"),
});
})
.await;
coordinators.push((handles, coord_key));
for composition in compositions {
test.provide_container(composition);
Expand Down
2 changes: 1 addition & 1 deletion tests/coordinator/src/tests/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub async fn sign(
#[tokio::test]
async fn sign_test() {
let _one_at_a_time = ONE_AT_A_TIME.get_or_init(|| Mutex::new(())).lock();
let (processors, test) = new_test();
let (processors, test) = new_test().await;

test
.run_async(|ops| async move {
Expand Down
2 changes: 2 additions & 0 deletions tests/docker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
chrono = "0.4"

tokio = { version = "1", default-features = false, features = ["sync"] }
Loading
Loading