dockertest 0.4 (#406)

* Updates to modern dockertest

* More updates to latest dockertest

* Update Cargo.lock to dockertest with handle restored

* clippy coordinator tests

* clippy full-stack tests

* Remove kayabaNerve branch for official repo's latest commit hash

* Update serai-client, remove reliance on the existence of a handle fn

* Don't use the hex encoding of unique_id in dockertests

Gets our hostnames just below 64 bytes, resolving test failures on at least
Debian-based systems.

* Use Network::Isolated for all dockertest instances

* Correct error from prior commit's edits
This commit is contained in:
Luke Parker
2023-10-23 06:59:38 -04:00
committed by GitHub
parent 0d23964762
commit c4bdbdde11
17 changed files with 178 additions and 196 deletions

View File

@@ -18,8 +18,8 @@ use serai_message_queue::{Service, Metadata, client::MessageQueue};
use serai_client::Serai;
use dockertest::{
PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, Composition,
DockerOperations,
PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy,
TestBodySpecification, DockerOperations,
};
#[cfg(test)]
@@ -30,13 +30,13 @@ static UNIQUE_ID: OnceLock<Mutex<u16>> = OnceLock::new();
pub fn coordinator_instance(
name: &str,
message_queue_key: <Ristretto as Ciphersuite>::F,
) -> Composition {
) -> TestBodySpecification {
serai_docker_tests::build("coordinator".to_string());
Composition::with_image(
TestBodySpecification::with_image(
Image::with_repository("serai-dev-coordinator").pull_policy(PullPolicy::Never),
)
.with_env(
.replace_env(
[
("MESSAGE_QUEUE_KEY".to_string(), hex::encode(message_queue_key.to_repr())),
("DB_PATH".to_string(), "./coordinator-db".to_string()),
@@ -53,13 +53,13 @@ pub fn coordinator_instance(
)
}
pub fn serai_composition(name: &str) -> Composition {
pub fn serai_composition(name: &str) -> TestBodySpecification {
serai_docker_tests::build("serai".to_string());
let mut composition = Composition::with_image(
TestBodySpecification::with_image(
Image::with_repository("serai-dev-serai").pull_policy(PullPolicy::Never),
)
.with_cmd(vec![
.replace_cmd(vec![
"serai-node".to_string(),
"--unsafe-rpc-external".to_string(),
"--rpc-cors".to_string(),
@@ -67,13 +67,14 @@ pub fn serai_composition(name: &str) -> Composition {
"--chain".to_string(),
"local".to_string(),
format!("--{}", name.to_lowercase()),
]);
composition.publish_all_ports();
composition
])
.set_publish_all_ports(true)
}
pub type Handles = (String, String, String);
pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F, Vec<Composition>) {
pub fn coordinator_stack(
name: &str,
) -> (Handles, <Ristretto as Ciphersuite>::F, Vec<TestBodySpecification>) {
let serai_composition = serai_composition(name);
let (coord_key, message_queue_keys, message_queue_composition) =
@@ -87,7 +88,7 @@ pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F,
let unique_id_mutex = UNIQUE_ID.get_or_init(|| Mutex::new(0));
let mut unique_id_lock = unique_id_mutex.lock().unwrap();
let first = *unique_id_lock == 0;
let unique_id = hex::encode(unique_id_lock.to_be_bytes());
let unique_id = *unique_id_lock;
*unique_id_lock += 1;
(first, unique_id)
};
@@ -107,14 +108,16 @@ pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F,
let mut compositions = vec![];
let mut handles = vec![];
for composition in [serai_composition, message_queue_composition, coordinator_composition] {
let name = format!("{}-{}", composition.handle(), &unique_id);
for (name, composition) in [
("serai_node", serai_composition),
("message_queue", message_queue_composition),
("coordinator", coordinator_composition),
] {
let handle = format!("coordinator-{name}-{unique_id}");
compositions.push(
composition
.with_start_policy(StartPolicy::Strict)
.with_container_name(name.clone())
.with_log_options(Some(LogOptions {
composition.set_start_policy(StartPolicy::Strict).set_handle(handle.clone()).set_log_options(
Some(LogOptions {
action: if std::env::var("GITHUB_CI") == Ok("true".to_string()) {
LogAction::Forward
} else {
@@ -122,18 +125,19 @@ pub fn coordinator_stack(name: &str) -> (Handles, <Ristretto as Ciphersuite>::F,
},
policy: LogPolicy::Always,
source: LogSource::Both,
})),
}),
),
);
handles.push(compositions.last().unwrap().handle());
handles.push(handle);
}
let coordinator_composition = compositions.last_mut().unwrap();
coordinator_composition.inject_container_name(handles.remove(0), "SERAI_HOSTNAME");
coordinator_composition.inject_container_name(handles.remove(0), "MESSAGE_QUEUE_RPC");
coordinator_composition.inject_container_name(handles[0].clone(), "SERAI_HOSTNAME");
coordinator_composition.inject_container_name(handles[1].clone(), "MESSAGE_QUEUE_RPC");
(
(compositions[0].handle(), compositions[1].handle(), compositions[2].handle()),
(handles[0].clone(), handles[1].clone(), handles[2].clone()),
message_queue_keys[&NetworkId::Bitcoin],
compositions,
)

View File

@@ -22,7 +22,7 @@ pub(crate) static ONE_AT_A_TIME: OnceLock<Mutex<()>> = OnceLock::new();
pub(crate) fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, DockerTest) {
let mut coordinators = vec![];
let mut test = DockerTest::new();
let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
for i in 0 .. COORDINATORS {
let (handles, coord_key, compositions) = coordinator_stack(match i {
0 => "Alice",
@@ -35,7 +35,7 @@ pub(crate) fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, Dock
});
coordinators.push((handles, coord_key));
for composition in compositions {
test.add_composition(composition);
test.provide_container(composition);
}
}
(coordinators, test)